Question: This is the link list question. Please help me solve it. Follows we define a singular linked list. Complete the implementation of the two functions
This is the link list question. Please help me solve it.
Follows we define a singular linked list. Complete the implementation of the two functions InsertNode and DeleteNode.
Note: You need to consider all special cases.
class Node { public: double data; //data
Node* next; //pointer to next };
class List { public: List(void) { head = NULL; } ~List(void); // constructor // destructor
bool IsEmpty() { return head == NULL; } Node* InsertNode(int index, double x); int DeleteNode(double x); private: Node* head;
};
//Parameters: //x: the data to be inserted //index: after insertion, the new node should be at position index // (the head of the list is at position 0) //returned value: a pointer to the new node; NULL if insertion fails Node* List::InsertNode(int index, double x) { //Complete the function here } //Parameters //x: the data of the node to be deleted //returned value: the position of the node deleted; -1 if no such node exists // (the head of the list is at position 0) int List::DeleteNode(double x) { //Complete the function here } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
