Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Refer to the lecture slides about dou ble linked lists and work on the following tasks a) Write a C program to implement the basic
Refer to the lecture slides about dou ble linked lists and work on the following tasks a) Write a C program to implement the basic operations of Double Linked List data structure. Declare and initialize (initNode()) the double linked list to add integer 22 as first data in the list. Guides for declaration and initialization struct Node [ int data; Node next; Node prev; tmpHead->datani tmpHead->next-NULL tmpHead->prev=NULL; b) Implement the following operations as functions i) Display all nodes in the entire list -displayNodes() ii) Add two new nodes (33 and 44) to existing list (at the end) addNode() Guides for displaying all nodes and adding new node. Node *cur = tmpHead; while (cur != NULL) { Node newNode = new Node ; newNode->data = n; newNode->next = NULL ; cout data next ! NU cout next cur->next = newNode; newNode->prev = cur; c) Implement the following operations as functions i) Add a new node (11) to the front of the list-addFront() ii) Remove a node from the list (in front)- removeFront) Guides for adding new node in front and removing the first node Node newNode = new Node ; newNode->data = n; newNode->next = tmpHead; newNode->prev = NULL; *tmpHead = newNode ; newNode->next->prev = newNode; if ( (*tmpHead)->next != NULL){ (*tmpHead) = (*tmpHead)->next; delete tmpHead)->prev; (*tmpHead)->prev = NULL; else cout
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