-
Notifications
You must be signed in to change notification settings - Fork 1
/
7. Queue Linear.cpp
105 lines (96 loc) · 1.83 KB
/
7. Queue Linear.cpp
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
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <process.h>
#define MAX 5
struct queue
{
int arr[MAX];
int f,r;
};
void insq(struct queue *,int);
void delq(struct queue *);
void display(struct queue *);
void main()
{
int ch,ele;
struct queue q;
q.f=-1;
q.r=0;
while(true)
{
system("cls");
printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n\n Enter Choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("Enter Element To Insert : ");
scanf("%d",&ele);
insq(&q,ele);
break;
case 2:delq(&q);
break;
case 3:display(&q);
break;
case 4:exit(0);
break;
default:printf("Invalid Selection");
}
getch();
}
}
void insq(struct queue *q,int ele)
{
if(q->r==MAX)
{
printf("Queue Full");
return;
}
q->arr[q->r]=ele;
q->r++;
if(q->f==-1)
q->f=0;
}
void delq(struct queue *q)
{
if(q->f==-1)
{
printf("Queue Empty");
return;
}
printf("Element Deleted is : %d",q->arr[q->f]);
q->f++;
if(q->f==q->r)
{
q->f=-1;
q->r=0;
}
}
void display(struct queue *q)
{
int i;
if(q->f==-1)
{
printf("Empty Queue");
return;
}
for(i=q->f;i<q->r;i++)
{
printf("%d ",q->arr[i]);
}
}
/*
License
=======
Copyright (C) 2011 SkyKOG
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/