Question: Complete the definitions given in the below code and show your implementation using with suitable main code. #include using namespace std; class Node { public:
Complete the definitions given in the below code and show your implementation using with suitable main code.
#include using namespace std;
class Node { public:
int data; Node * next;
Node() {
data = 0; next = NULL;
}
Node(int d) {
data = d; }
};
class CircularLinkedList { public:
Node * head;
CircularLinkedList() { head = NULL;
}
// 1. Check if node exists using key value Node * nodeExists(int k)
// 2. Append a node to the list
void insertAtLast(Node * new_node);
// 3. Prepend Node - Attach a node at the start void insertAtBegin(Node * new_node);
// 4. Insert a Node after a particular node in the list void insertAfter(int k, Node * new_node);
// 5. Delete node by given key void deleteNodeByKey(int k);
// 6th update node by given data
void updateNodeByKey(int new_data);
// 7th printing void printList();
};
int main() {
CircularLinkedList obj; Node *n = new Node(); n->data = 5;
n->next = NULL;
Node *n2 = new Node(); n2->data = 3;
n2->next = NULL;
obj.prependNode(n); obj.printList(); obj.prependNode(n2); obj.printList();
return 0; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
