Skip to content

Commit 3ea60ba

Browse files
committed
feat : new learning DSA Linked List
1 parent 65f9fd0 commit 3ea60ba

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

DSA/LinkedList/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import "fmt"
4+
5+
type Node struct {
6+
data int
7+
next *Node
8+
}
9+
type LinkedList struct {
10+
head *Node
11+
}
12+
13+
func (l *LinkedList) Insert(value int) {
14+
var newNode = new(Node)
15+
newNode.data = value
16+
newNode.next = l.head
17+
l.head = newNode
18+
}
19+
func (l *LinkedList) Print() {
20+
var temp = l.head
21+
for temp != nil {
22+
fmt.Println(temp.data)
23+
temp = temp.next
24+
}
25+
26+
fmt.Println()
27+
}
28+
func main() {
29+
var l = new(LinkedList)
30+
l.Insert(1)
31+
l.Insert(2)
32+
l.Insert(3)
33+
l.Insert(4)
34+
l.Insert(5)
35+
36+
l.Print()
37+
}

0 commit comments

Comments
 (0)