-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueUsingCLLUsingHeaderNode.c
More file actions
102 lines (96 loc) · 1.9 KB
/
QueueUsingCLLUsingHeaderNode.c
File metadata and controls
102 lines (96 loc) · 1.9 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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
typedef struct node *NODE;
NODE getnode()
{
NODE x;
x=(NODE)malloc(sizeof(struct node));
if(x==NULL)
{
printf(" OUT OF MEMORY \n");
exit(0);
}
return x;
}
void freenode(NODE x)
{
free(x);
}
void Display(NODE head)
{
NODE temp;
if(head->link==head)
{
printf(" List is empty \n");
return head;
}
printf(" Contents of the list are \n");
temp=head->link; // address of first node
while(temp!=head)
{
printf("%d",temp->info);
temp=temp->link;
}
printf("\n");
}
NODE insert_rear(int item,NODE head)
{
NODE temp,cur;
temp=getnode(); // create a node
temp->info=item;
cur=head->link; // address of first node
while(cur->link!=head)
{
cur=cur->link;
}
cur->link=temp;
temp->link=head;
return head;
}
NODE delete_front(NODE head)
{
NODE temp;
if(head->link==head)
{
printf(" List is empty \n");
return NULL;
}
temp=head->link; // address of first node
head->link=temp->link;
printf(" Item deleted is %d \n",temp->info);
freenode(temp);
return head;
}
void main()
{
NODE head;
int choice,item;
head=getnode();
head->info=0;
head->link=head;
for(;;)
{
printf(" 1: delete front 2: insert rear \n");
printf(" 3: display 4: exit \n");
printf(" Enter choice \n");
scanf("%d",&choice);
switch(choice)
{
case 1:head=delete_front(head);
break;
case 2:printf(" Enter the item to be inserted \n ");
scanf("%d",&item);
head=insert_rear(item,head);
break;
case 3:Display(head);
break;
default: exit(0);
}
}
}