-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
130 lines (94 loc) · 2.45 KB
/
main.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"fmt"
"github.com/MuhammadSaim/dsa-with-go/linkedlist/doubly"
"github.com/MuhammadSaim/dsa-with-go/linkedlist/singly"
)
func main() {
// initialize the linkedlist
linkedList := &singly.LinkedList{}
// display the list
linkedList.Display()
// insret at start
linkedList.InsertAtStart(4)
linkedList.InsertAtStart(5)
// insert at end
linkedList.InsertAtEnd(10)
linkedList.InsertAtEnd(12)
linkedList.InsertAtEnd(13)
linkedList.InsertAtEnd(15)
linkedList.InsertAtEnd(11)
linkedList.InsertAtEnd(10)
linkedList.InsertAtEnd(23)
linkedList.InsertAtEnd(14)
linkedList.InsertAtEnd(78)
linkedList.InsertAtEnd(11)
linkedList.InsertAtEnd(90)
linkedList.InsertAtEnd(14)
// display the list
linkedList.Display()
// remove duplicates
linkedList.RemoveDuplicate()
// display the list
linkedList.Display()
// find in list
linkedList.Find(3)
// display the list
linkedList.Display()
// middle of the list
linkedList.Middle()
// linear search
linkedList.LinearSearch(12)
linkedList.LinearSearch(190)
// display the list
linkedList.Display()
// reverse the linkedlist
linkedList.Reverse()
// display the list
linkedList.Display()
// count the list
fmt.Printf("Total nodes in the list are: %d\n", linkedList.Count())
//delete by value
linkedList.DeleteByValue(12)
linkedList.DeleteByValue(4)
// display the list
linkedList.Display()
// delete from the start
linkedList.DeleteFromStart()
linkedList.DeleteFromStart()
// delete from the end
linkedList.DeleteFromEnd()
linkedList.DeleteFromEnd()
linkedList.DeleteFromEnd()
// display the list
linkedList.Display()
// count the list
fmt.Printf("Total nodes in the list are: %d\n", linkedList.Count())
// delete from the end
linkedList.DeleteFromEnd()
linkedList.DeleteFromEnd()
linkedList.DeleteFromEnd()
linkedList.DeleteFromEnd()
// display the list
linkedList.Display()
// insert at end
linkedList.InsertAtEnd(10)
linkedList.InsertAtEnd(12)
linkedList.InsertAtEnd(13)
// check linked list is cycle
linkedList.DetectCycle()
print("\n\nDoubly Linked List\n\n")
// doubly linked list
doublyLinkedList := &doubly.LinkedList{}
// display the list
doublyLinkedList.Display()
// insret at start
doublyLinkedList.InsertAtStart(4)
doublyLinkedList.InsertAtStart(5)
// count the list
fmt.Printf("Total node in the list are %d\n", doublyLinkedList.Count())
// find in list
doublyLinkedList.Find(3)
// display the list
doublyLinkedList.Display()
}