Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

assume that a circular doubly linked list has been created, as in figure 3.29. t

ID: 3562561 • Letter: A

Question

assume that a circular doubly linked list has been created, as in figure 3.29. the qestion asks that after each of the following assignments, indicate changes made in the list by showing which links have been modified. the second assignment should make changes in the list modified by the first assignment and so on. list--> next --> next --> next = --> list--> prev; list--> prev -->prev --> prev = list --> next--> next--> next--> prev; list? next--> next--> next--> prev = list--> prev--> prev--> prev; list? next = list--> next--> next list? next--> prev--> next = list--> next--> next--> next; how many nodes does the shortest linked list have? the longest linked list?

Explanation / Answer

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct dcll
{
int data;
struct dcll *next, *previous;
};
typedef struct dcll node;
static int count;
void main()
{
int choice;
node *head=NULL;
void create(node*);
node* insertfirst(node*);
void insertlast(node*);
node* deletefirst(node*);
void deletelast(node*);
void reverse(node*);
void display(node*);

do
{
printf(" Choices");
printf(" 1.Create");
printf(" 2.Insert First");
printf(" 3.Insert Last");
printf(" 4.Delete First");
printf(" 5.Delete Last");
printf(" 6.Reverse");
printf(" 7.Display");
printf(" 8.Exit");
printf(" Enter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
if(head!=NULL)
{
printf("cant create the list as list is not null");
break;
}
else
{
head=(node*)malloc(sizeof(node));
head->next=NULL;
head->previous=NULL;
create(head);
display(head);
break;
}
}
case 2:
{
head=insertfirst(head);
display(head);
break;
}
case 3:
{
insertlast(head);
display(head);
break;
}
case 4:
{
head=deletefirst(head);
display(head);
break;
}
case 5:
{
deletelast(head);
display(head);
break;
}
case 6:
{
reverse(head);
break;
}
case 7:
{
display(head);
break;
}
case 8:
{
exit (0);
}
Default:
{
printf(" Enter the Right Choice");
}
}
}while(choice!=8);
}

void create(node *list)
{
node*head;
node*last;
int x;
printf(" Enter the value: ");
scanf("%d",&x);
if (x!=0)
{
count++;
list->data=x;
list->previous=list;
list->next=(node*)malloc(sizeof(node));
create(list->next);

}
else
list->next=last;
}
void display(node *list)
{
int i;
printf(" Created List:HEAD <=> ");
if(list==NULL)
printf("The List is Empty");
else
{
for(i=1;i<=count;i++,list=list->next)
printf("%d <=> ",list->data);
}
printf("NULL");
printf(" No. of Nodes: %d",count);
}

void reverse(node *list)
{
if(list==NULL)
{
printf(" List is Empty");
}
else
{
if(list->next!=NULL)
{
reverse(list->next);
printf(" <=> %d",list->data);
}
}
node* insertfirst(node*last)
{
node *newnode;

newnode=(node*)malloc(sizeof(node));
printf(" Enter the Value: ");
scanf("%d",&newnode->data);

newnode->previous=last;
newnode->next=head;
last->next=newnode;
head->previous=newnode;
head=newnode;
count++;
return (newnode);
}
void insertlast(node *list)
{
node *newnode;
while(list!=NULL)
{
count++;
newnode=(node*)malloc(sizeof(node));
printf(" Enter the Value: ");
scanf("%d",&newnode->data);
newnode->next=head;
last->next=newnode;
newnode->previous=last;
head->previous=newnode;
break;
}
printf(" No Such Data");
}
node *deletefirst(node*list)
{

list=list->next;
count--;
list->previous=NULL;
return(list);
}
void deletelast(node *list)
{
node*temp;
while(list!=NULL)
{
temp=last;
last->previous->next=head;
head->previous=list;
count--;
free(temp);
list=last;
break;
}
last=list->next;

}
printf("No Such Data");
printf(" No of Nodes: %d",count);
}