-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathSimple_queue.c
83 lines (82 loc) · 1.51 KB
/
Simple_queue.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdlib.h>
#include <stdio.h>
int pos=1;
struct node
{
int data;
struct node *next;
}*start=NULL;
void insert_pos()
{
struct node *tp,*c;
tp=(struct node *)malloc(sizeof(struct node));
if(start==NULL)
{
printf("Enter the data: ");
scanf("%d",&tp->data);
tp->next=NULL;
start=tp;
return;
}
c=start;
for(int i=1;i<pos;i++)
c=c->next;
if(c==NULL)
printf("%d",c->data);
printf("Enter the data: ");
scanf("%d",&tp->data);
tp->next=c->next;
c->next=tp;
pos++;
}
void del_first()
{
struct node *temp;
temp=start;
printf("Poped data is: %d\n",temp->data);
start=start->next;
free(temp);
printf("Node deleted sucessfully...\n");
}
void display()
{
struct node *p;
if(start==NULL)
{
printf("No node present.\n");
return;
}
p=start;
while(p!=NULL)
{
printf("%d\n",p->data);
p=p->next;
}
}
int main()
{
int a,i=0,ch;
printf("Enter 1 to push the data.\n");
printf("Enter 2 to pop the data.\n");
printf("Enter 3 to display the data.\n");
while(1)
{
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert_pos();
break;
case 2:
del_first();
break;
case 3:
display();
printf("Underflow...\n");
break;
default:
exit(0);
}
}
}