Question: Implement several basic methods for a singly linked list. Implement the following LinkedList methods in linkedlist.cpp: void add ( int N ) Add N to
Implement several basic methods for a singly linked list.
Implement the following LinkedList methods in linkedlist.cpp:
void add ( int N ) Add N to the front of the linked list.
bool remove ( int N ) Remove the first instance of N from the list, then return true. If the N was not found, return false.
int find ( int N ) Find the first instance of N in the list and return its index. Return -1 if N was not found.
int count ( int N ) Return a count of the instances of N in the list.
int at ( int N ) Return the value stored in the node at index N.
int len() Return the current length of the list.
#include "node.h" using namespace std;
class LinkedList { Node * head; int length; public: void add( int ); bool remove( int ); int find( int ); int count( int ); int at( int ); int len(); };
class Node { public: Node * next; int value; };
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
