Skip to content

Commit 060af54

Browse files
committed
chore: implement a print linked list
1 parent 9b8e6f3 commit 060af54

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

arr_m.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func arrayManipulation(n int32, queries [][]int32) int64 {
3636
return max
3737
}
3838

39-
func main() {
40-
queries := [][]int32{
41-
{1, 2, 100},
42-
{2, 5, 100},
43-
{3, 4, 100},
44-
}
45-
fmt.Println(arrayManipulation(5, queries))
46-
}
39+
// func main() {
40+
// queries := [][]int32{
41+
// {1, 2, 100},
42+
// {2, 5, 100},
43+
// {3, 4, 100},
44+
// }
45+
// fmt.Println(arrayManipulation(5, queries))
46+
// }

linked_list.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
type node struct {
4+
value int
5+
next *node
6+
}
7+
8+
type list struct {
9+
head *node
10+
}
11+
12+
func (l *list) insert(n *node) {
13+
if l.head == nil {
14+
l.head = n
15+
} else {
16+
curr := l.head
17+
for curr.next != nil {
18+
curr = curr.next
19+
}
20+
curr.next = n
21+
}
22+
}
23+
24+
func main() {
25+
n := &node{value: 1}
26+
lst := list{}
27+
n1 := &node{value: 2}
28+
n2 := &node{value: 3}
29+
n3 := &node{value: 4}
30+
n4 := &node{value: 5}
31+
lst.insert(n)
32+
33+
lst.insert(n1)
34+
lst.insert(n2)
35+
lst.insert(n3)
36+
lst.insert(n4)
37+
38+
for n != nil {
39+
println(n.value)
40+
n = n.next
41+
}
42+
}

rotate_left.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
package main
22

3-
/*
4-
* Complete the 'rotateLeft' function below.
5-
*
6-
* The function is expected to return an INTEGER_ARRAY.
7-
* The function accepts following parameters:
8-
* 1. INTEGER d
9-
* 2. INTEGER_ARRAY arr
10-
*/
11-
123
func rotateLeft(d int32, arr []int32) []int32 {
134
rotate := d % int32(len(arr))
145
lenArr := len(arr) - 1

0 commit comments

Comments
 (0)