-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (53 loc) · 1.39 KB
/
Copy pathmain.go
File metadata and controls
73 lines (53 loc) · 1.39 KB
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
package main
import (
"fmt"
"strconv"
"github.com/whalelogic/Go-Programming/ll"
"github.com/whalelogic/Go-Programming/sort"
"github.com/whalelogic/Go-Programming/stack"
"github.com/whalelogic/Go-Programming/recursion"
)
func fib(n int) int {
if n <= 1 {
return n
}
return fib(n-1) + fib(n-2)
}
var myList ll.List[int]
func main() {
// Stack example
arr2 := []int{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}
sortedArr := sort.Sort(arr2)
fmt.Println(sortedArr)
arr := stack.Stack{}
arr.Push(10)
arr.Print()
// Linked List example
myList.PushBack(10)
myList.PushBack(20)
myList.PushFront(5)
myList.InsertAfter(myList.Front(), 7)
myList.InsertAfter(myList.Front(), 13)
fmt.Println("Linked List elements:")
// loop through the list and print elements
for e := myList.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value)
}
fmt.Println("First element: ", myList.Front().Value)
fmt.Println("Last element: ", myList.Back().Value)
fmt.Println("Length of linked-list: ", myList.Length())
sl := myList.MakeSlice()
for i := range sl {
// Must convert int to string to concatenate
fmt.Println(strconv.Itoa(i) + ": " + strconv.Itoa(sl[i]))
}
v, ok := myList.RemoveFront()
if ok {
fmt.Println("Removed front element: ", v)
}
fact := recursion.Factor(5)
var t []string
t = append(t, "Factorial of 5 is: "+strconv.Itoa(fact))
print(t)
fmt.Println("Fibonacci of 7 is: ", fib(7))
}