-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathque.c
100 lines (89 loc) · 1.38 KB
/
que.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//Author: Dashrath Chauhan (Semester 3 -> GEC Dahod)
//Last Modified: Febrauary 2014
//Program: Queue using Array
#include<stdio.h>
#define size 10
int q[size];
int front=-1;
int rear=-1;
int insert()
{
int x;
if(rear==size-1)
{
printf("Queue overflow. You can not insert more elements.\n");
return 0;
}
{
if(front<=-1)
{
front=0;
}
printf("Enter the element:");
scanf("%d", &x);
rear=rear+1;
q[rear]=x;
}
printf("\nAfter inserting:\n");
printf("Rear = %d", rear);
printf("\nFront = %d\n", front);
}
int delete()
{
if(front<=-1 || front>rear)
{
printf("Queue is empty. No more elements to remove.\n");
return 0;
}
else
{
printf("Deleted element is :%d", q[front]);
front=front+1;
}
printf("\nAfter deleting:\n");
printf("Rear = %d\n", rear);
printf("Front = %d\n", front);
}
int display()
{
int i;
if(front>rear)
{
printf("Queue is Empty. No elements to display.\n");
return 0;
}
else
{
for(i=front; i<=rear; i++)
{
printf("%d|", q[i]);
}
}
}
main()
{
int c;
printf("\vRear = %d", rear);
printf("\nFront = %d", front);
do
{
printf("\n1.INSERT\n");
printf("2.DELETE\n");
printf("3.DISPLAY\n");
printf("4.Exit\n");
printf("Enter your choice:");
scanf("%d", &c);
switch(c)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
}
}while(c!=4);
}