Question: insert at beginning, update and Reverse a list for an assignment on circularly doubly linked lists. I've figured out how to insert at beginning. But

 insert at beginning, update and Reverse a list for an assignment on circularly doubly linked lists. I've figured out how to insert at beginning. But the update function and reverse is giving me some trouble. Could you tell me what's wrong with my update function and how to make the reverse sort work ? The code is below

/*

* C++ Code to Implement Circular Doubly Linked List

* Examples of Operations on Doubly Linked List

*/

#include

using namespace std;

//Node Declaration

struct Node

{

int info;

struct Node *next;

struct Node *prev;

};

Node *start, *last; //Global scope

int counter = 0; //Global scope

void continueClear(){

cout\" press>

cin.ignore();cin.ignore();

system(\"clear\");

}

//Selection menu

int menu(){

int c;

cout

cout\"operations>

cout

cout\"1.insert>

cout\"2.insert>

cout\"3.update>

cout\"4.search>

cout

cout\"6.reverse>

cout\"7.display>

cout

cout\" enter>

cin>>c;

return c;

}

//Define prototype of functions in use

Node* create_node(int);

void insert_begin();

void search();

void sort();

void display();

//Prototype for assignment functions

void insert_end();

void update(int info);

void reverse_list();

//Main: Contains Menu

int main()

{

int choice=0;

do

{

choice=menu();

switch(choice)

{

case 1:

insert_begin();

break;

case 2:

insert_end();

cout\" ??????>

break;

case 3:

update(5);

cout\" ??????>

break;

case 4:

search();

break;

case 5:

sort();

break;

case 6:

//reverse_list();

cout\" ??????>

break;

case 7:

display();

break;

case 8:

break;

default:

cout\"wrong>

}

continueClear();

} while (choice!=8);

return 0;

}

//Function to create node - allocate memory dynamically

Node* create_node(int value)

{

counter++; //Global variable

Node *temp;

temp = new Node;

temp->info = value;

temp->next = NULL;

temp->prev = NULL;

return temp;

}

//Insert at the beginning

void insert_begin()

{

int value;

cout\"enter>

cin>>value;

struct Node *temp;

temp = create_node(value);

if (start == last && start == NULL)

{

cout\"element>

start = last = temp;

start->next = last->next = NULL;

start->prev = last->prev = NULL;

}

else

{

temp->next = start;

start->prev = temp;

start = temp;

start->prev = last;

last->next = start;

cout\"element>

}

}

void insert_end()

{

int value;

cout

cin >> value;

struct Node *temp;

temp = create_node(value);

if (start == last && start == NULL)

{

cout\"element>




Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!