-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCIRCDLL.CPP
More file actions
145 lines (129 loc) · 2.26 KB
/
CIRCDLL.CPP
File metadata and controls
145 lines (129 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct circdlist
{
int info;
struct circdlist *left,*right;
};
circdlist* getnode()
{
circdlist *t;
t=(struct circdlist*)(malloc(sizeof(struct circdlist)));
if(t==NULL)
{
printf("Memory not available\n");
return NULL;
}
else {
return t;
}
}
circdlist* insertf(circdlist *h,int item)
{
circdlist *temp,*c,*p;
temp=getnode();
temp->info=item;
c=h->right;
h->right=temp;
temp->left=h;
temp->right=c;
c->left=temp;
return h;
}
circdlist* insertr(circdlist *h,int item)
{
circdlist *temp,*p,*c=h;
temp=getnode();
temp->info=item;
c=h->left;
h->left=temp;
temp->right=h;
temp->left=c;
c->right=temp;
return h;
}
circdlist* deletef(circdlist *h)
{
circdlist *temp,*c;
if(h->right==h)
{
printf("List is empty\n");
return h;
}
c=h->right;
temp=c->right;
h->right=temp;
temp->left=h;
printf("Item deleted =%d",c->info);
free(c);
return h;
}
circdlist* deleter(circdlist *h)
{
circdlist *temp,*c,*p;
if(h->left==h)
{
printf("List is empty\n");
return NULL;
}
c=h->left;
temp=c->left;
h->left=temp;
temp->right=h;
printf("Item deleted =%d",c->info);
free(c);
return h;
}
void display(circdlist *h)
{
circdlist *temp=h->right;
if(h->right==h)
{
printf("circdlist empty, nothing to display\n");
return;
}
else
{
printf("elements are\n");
while(temp!=h)
{
printf(" %d",temp->info);
temp=temp->right;
}
}
}
int main(void)
{
struct circdlist *head=NULL;
head->right=head->left=head;
int ch,item;
clrscr();
for(;;)
{
printf("\nMENU\n1:INSERT FRONT\n2:INSERT REAR\n3:DELETE FRONT\n4:DELETE REAR\n5:DISPLAY \n6:EXIT");
printf("\nenter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nenter item to be inserted in front\n");
scanf("%d",&item);
head=insertf(head,item);
break;
case 2:printf("\nenter item to be inserted in rear\n");
scanf("%d",&item);
head=insertr(head,item);
break;
case 3:head=deletef(head);
break;
case 4:head=deleter(head);
break;
case 5:display(head);
break;
default:exit(0);
}
}
return 0;
}