-
Notifications
You must be signed in to change notification settings - Fork 0
/
linearQueue.c
81 lines (63 loc) · 1.11 KB
/
linearQueue.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
//
// main.c
// queue
//
// Created by Pooshan Vyas on 8/24/15.
// Copyright © 2015 Pooshan Vyas. All rights reserved.
//
/*
isEmpty()
isFull()
atFront()
insert(type element)
del()
As like queue in real life: Insert from rear and Delete from front
*/
#include <stdio.h>
#define size 5
int queue[size];
int front = -1, rear = -1;
int isEmpty()
{
if (front == -1)
return 1;
else
return 0;
}
int isFull()
{
if (rear == size-1)
return 1;
else
return 0;
}
int atFront(){
return queue[front];
}
void insert(int element){
if (isFull())
printf("\n Queue is full");
else{
if (rear==-1)
front=rear=0;
else
rear++;
queue[rear]=element;
}
}
void del(){
if (isEmpty()==1)
printf("\n Queue is empty");
else
{
if(front==rear)
front=rear=-1;
else
front++;
}
}
int main() {
insert(10); insert(11); insert(101); insert(21); insert(50);
del(); del(); del();
printf("on the top we have %d \n", atFront());
}