-
Notifications
You must be signed in to change notification settings - Fork 0
/
sll_ins_del_test.go
57 lines (51 loc) · 1.59 KB
/
sll_ins_del_test.go
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
/*
#created_on : 27 Dec 2016,Tuesday(afternoon)
#coded_by : hygull
*/
package ds
import (
"fmt"
"testing"
)
func TestInsertNodeAtBeginningAndEnd(t *testing.T) {
var start *Node //start woill point to 1st node of singly linked list
fmt.Println("\n********* Testing (Inserting & deleting nodes at beginning & end of the linked list) **********\n")
node := CreateNode("Hygull", 24)
start = InsertSllNodeAtBeginning(start, node) //We can also use the global START variable
/*
+---------------+----+
start-->| {"Hygull",24} | nil|
+--------------------+
*/
node2 := CreateNode("Hemkesh", 22)
start = InsertSllNodeAtBeginning(start, node2)
/*
+---------------+----+ +----------------+----+
start===>| {"Hemkesh",22}| ======>| {"Hygull", 24} | nil|
+---------------+----+ +----------------+----+
*/
node3 := CreateNode("Darshan", 23)
start = InsertSllNodeAtEnd(start, node3)
/*
+---------------+----+ +----------------+----+ +----------------+----+
start===>| {"Hemkesh",22}| ======>| {"Hygull", 24} | =======>| {"Darshan",23} | nil|
+---------------+----+ +----------------+----+ +----------------+----+
*/
ShowNodes(start)
fmt.Println()
ShowNodesHierarchy(start)
fmt.Println()
recordsList := GetNodesRecords(start)
if len(recordsList) == 0 {
fmt.Println("Singly linked list is empty")
}
fmt.Println()
marshalledRecords, _ := Marshall(recordsList)
fmt.Println(marshalledRecords)
start = nil
err := ShowNodes(start)
if err != nil {
fmt.Println(err) //singly linked list is empty
}
fmt.Println("DONE...")
}