Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started