-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.go
72 lines (49 loc) · 779 Bytes
/
queue.go
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
package main
import "fmt"
const SIZE uint8 = 5
var items [SIZE]int
var front, rear = -1, -1
func enqueue(item int) {
if uint8(rear) == SIZE-1 {
fmt.Println("Queue is Full!!!")
} else {
if front == -1 {
front = 0
}
rear++
items[rear] = item
}
}
func dequeue() {
if rear == -1 {
fmt.Println("Queue is Empty!!!")
} else {
fmt.Println("Deleted item:", items[front])
front++
if front > rear {
front, rear = -1, -1
}
}
}
func display() {
if rear == -1 {
fmt.Println("Queue is Empty!!!")
} else {
fmt.Println("Queue Items:")
for i := rear; i >= front; i-- {
fmt.Println(items[i])
}
}
}
func main() {
enqueue(2)
enqueue(3)
enqueue(4)
enqueue(5)
enqueue(6)
display()
dequeue()
dequeue()
dequeue()
display()
}