Skip to content

Commit 5918b6c

Browse files
committed
add even or odd linkedlist
1 parent a92cbbe commit 5918b6c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
import "fmt"
3+
4+
// has two fields [data] of type integer and [next] of type *node (holds the memory address of next node)
5+
type node struct {
6+
data int
7+
next *node
8+
}
9+
//has three fields length, head and tail node
10+
type LinkedList struct {
11+
length int
12+
head *node
13+
tail *node
14+
}
15+
16+
func (ll *LinkedList) IsLengthEven() bool {
17+
current := ll.head
18+
for current != nil && current.next != nil {
19+
current = current.next.next
20+
}
21+
if current != nil {
22+
return false
23+
}
24+
return true
25+
}

0 commit comments

Comments
 (0)