-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathADT_Linklist_as_Queue_insert_delete.c
69 lines (65 loc) · 1.73 KB
/
ADT_Linklist_as_Queue_insert_delete.c
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
// author: jaydattpatel
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct Node
{
int data;
struct Node *next;
}*rear=NULL,*front=NULL;
void insert()
{
int a;
printf("\nEnter Value:"); scanf("%d",&a);
struct Node *newnode;
newnode = (struct Node*)malloc(sizeof(struct Node));
newnode->data = a;
newnode->next = NULL;
if (front == NULL) front = rear = newnode;
else
{ rear->next = newnode; rear = newnode; }
printf("Insertion Successfull !!\n");
};
void delete()
{
if(front == NULL) printf("Queue is emplty !!!\n");
else
{
struct Node *temp = front;
front = front->next;
printf("Deleted Elemet is %d",temp->data);
free(temp);
}
};
void display()
{
if(front == NULL)
printf("Queue is emplty !!!\n");
else
{
struct Node *f = front,*r = rear;
while (f->next != r->next)
{ printf("%d\n",f->data); f = f->next; }
if (f->next == r->next) printf("%d\n",r->data);
}
};
int main()
{
int value,choice;
while(1)
{
printf("\n--------queue implement Menu -------------");
printf("\n1.Insert\t2.Delete\t3.Display\t4.Exit");
printf("\nEnter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: { insert(); break; }
case 2: { delete(); break; }
case 3: { display(); break; }
case 4: { exit(0); }
default:{printf("\nFunction Terminated."); exit(0);}
}
}
return(0);
}