Skip to content

Commit a257713

Browse files
committed
linkedList Algorithms
1 parent 31bad2b commit a257713

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

linkedList/doublyLinkedList.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package main
2+
3+

linkedList/linkedList.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package linkedList
2+
3+
import ("fmt"
4+
//"reflect"
5+
)
6+
7+
type linkedList struct {
8+
data int
9+
next *linkedList
10+
}
11+
12+
func insertll(ll_head *linkedList,data int) {
13+
temp := ll_head
14+
for temp.next != nil {
15+
temp = temp.next
16+
}
17+
temp.next = new(linkedList)
18+
temp.next.data = data
19+
}
20+
21+
func printll(ll_head *linkedList) {
22+
temp := ll_head
23+
for temp.next != nil {
24+
fmt.Println(temp.data)
25+
temp = temp.next
26+
}
27+
// Last element in the linked list
28+
fmt.Println(temp.data)
29+
}
30+
// Unit Test function
31+
func main() {
32+
33+
var head *linkedList = new(linkedList)
34+
// initializing the head variable
35+
head.data = 5
36+
37+
insertll(head,5)
38+
insertll(head,10)
39+
insertll(head,20)
40+
41+
printll(head)
42+
/*
43+
fmt.Println(head)
44+
fmt.Println(head.next)
45+
fmt.Println(head.next.next)
46+
fmt.Println(head.next.next.next)
47+
*/
48+
//fmt.Println(ll.next.data)
49+
//fmt.Println(reflect.TypeOf(ll.next.data))
50+
}

0 commit comments

Comments
 (0)