-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssl_node_display.go
63 lines (57 loc) · 1.91 KB
/
ssl_node_display.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
58
59
60
61
62
63
/*
{
"date_of_creation" => "27 Dec 2016, Tuesday(morning)",
"aim_of_program" => "Displaying nodes information",
"coded_by" => "hygull",
"Go_version" => "1.7.1",
}
*/
package ds
import "errors"
import "fmt"
//A fuunction that displays all the nodes hierarchy by marshalling the complete list, if list is empty,
//or if there's a any problem in marshalling, then throws an error
func ShowNodesHierarchy(__startNodePtr *Node) error {
if __startNodePtr == nil {
return errors.New("singly linked list is empty")
}
listAsSlice, err := Marshall(*__startNodePtr)
if err != nil {
return err
}
fmt.Println()
fmt.Println(string(listAsSlice))
return nil
}
//A fuunction that displays all the nodes by marshalling it, if list is empty,
//or if there's a any problem in marshalling, then throws an error
func ShowNodes(__startNodePtr *Node) error {
if __startNodePtr == nil {
return errors.New("singly linked list is empty")
}
fmt.Println()
i := 1
for __startNodePtr != nil {
nodeRecordAsSlice, err := Marshall((*__startNodePtr).Record)
if err != nil {
return err
}
fmt.Println("--------------------- Record at Node" + fmt.Sprint(i) + " -----------------------------")
fmt.Println(string(nodeRecordAsSlice))
fmt.Println()
__startNodePtr = __startNodePtr.Next
i++
}
fmt.Println("----------------------------END------------------------------------")
return nil
}
//A function that returns a list of maps(each represents the data part of node in singly linked list)
//There is no need to return error type, if list is empty then return a empty slice of maps
func GetNodesRecords(__startNodePtr *Node) []map[string]interface{} {
nodeRecords := []map[string]interface{}{}
for __startNodePtr != nil {
nodeRecords = append(nodeRecords, __startNodePtr.Record)
__startNodePtr = __startNodePtr.Next
}
return nodeRecords //list of maps...[] (empty slice in case, if list is empty)/[...](non-empty slice)
}