-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.go
More file actions
69 lines (50 loc) · 1.2 KB
/
example.go
File metadata and controls
69 lines (50 loc) · 1.2 KB
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
/**
*
* @Name: Go - Data Structure and Algorithm (Queue Linked-List)
* @Author: Max Base
* @Date: 2022/10/12
* @Repository: https://github.com/BaseMax/QueueLinkedListGo
* @License: GPL-3.0
*
*/
package main
import "fmt"
func main() {
// Create a new queue
queue := NewQueueLinkedList()
// Add some elements to the queue
queue.Enqueue(1)
queue.Enqueue(2)
queue.Enqueue(3)
queue.Enqueue(4)
// Peek the first element
fmt.Println(queue.Peek())
// Peek the last element
fmt.Println(queue.PeekTail())
// Print the queue
queue.Print()
// Reverse the queue
queue.Reverse()
// Print the queue
queue.Print()
// Pop the first element
fmt.Println(queue.Dequeue())
// Pop the last element
fmt.Println(queue.DequeueTail())
// Print the queue
queue.Print()
// Reverse the queue (recursive)
queue.head = queue.ReverseRecursive(queue.head)
// Print the queue
queue.Print()
// Clear the queue
queue.Clear()
// Print the queue
queue.Print()
// Check if the queue is empty
fmt.Println(queue.IsEmpty())
// Add some elements to the queue
queue.Enqueue(1)
// Check if the queue is empty
fmt.Println(queue.IsEmpty())
}