-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsll_node_create.go
105 lines (97 loc) · 3.15 KB
/
sll_node_create.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package ds
import "fmt"
//Defining the singly linked list Node
type Node struct {
Record map[string]interface{}
Next *Node
}
//A function that creates a node for singly lint based on the information provided (as list of data)
func CreateNode(compulsoryData interface{}, data ...interface{}) *Node {
tempMap := make(map[string]interface{})
node := Node{}
dataName := "Data"
data = append(data, compulsoryData)
for index, item := range data {
switch t := item.(type) {
case int:
tempMap[dataName+fmt.Sprint(index)] = item.(int)
case []int:
tempMap[dataName+fmt.Sprint(index)] = item.([]int)
case int8:
tempMap[dataName+fmt.Sprint(index)] = item.(int8)
case []int8:
tempMap[dataName+fmt.Sprint(index)] = item.([]int8)
case int16:
tempMap[dataName+fmt.Sprint(index)] = item.(int16)
case []int16:
tempMap[dataName+fmt.Sprint(index)] = item.([]int16)
case int32:
tempMap[dataName+fmt.Sprint(index)] = item.(int32)
case []int32:
tempMap[dataName+fmt.Sprint(index)] = item.([]int32)
case int64:
tempMap[dataName+fmt.Sprint(index)] = item.(int64)
case []int64:
tempMap[dataName+fmt.Sprint(index)] = item.([]int64)
case uint:
tempMap[dataName+fmt.Sprint(index)] = item.(uint)
case uint8:
tempMap[dataName+fmt.Sprint(index)] = item.(uint8)
case uint16:
tempMap[dataName+fmt.Sprint(index)] = item.(uint16)
case uint32:
tempMap[dataName+fmt.Sprint(index)] = item.(uint32)
case uint64:
tempMap[dataName+fmt.Sprint(index)] = item.(uint64)
case []uint:
tempMap[dataName+fmt.Sprint(index)] = item.([]uint)
case []uint8:
tempMap[dataName+fmt.Sprint(index)] = item.([]uint8)
case []uint16:
tempMap[dataName+fmt.Sprint(index)] = item.([]uint16)
case []uint32:
tempMap[dataName+fmt.Sprint(index)] = item.([]uint32)
case []uint64:
tempMap[dataName+fmt.Sprint(index)] = item.([]uint64)
case bool:
tempMap[dataName+fmt.Sprint(index)] = item.(bool)
case []bool:
tempMap[dataName+fmt.Sprint(index)] = item.([]bool)
case uintptr:
tempMap[dataName+fmt.Sprint(index)] = item.(uintptr)
case []uintptr:
tempMap[dataName+fmt.Sprint(index)] = item.([]uintptr)
case float32:
tempMap[dataName+fmt.Sprint(index)] = item.(float32)
case []float32:
tempMap[dataName+fmt.Sprint(index)] = item.([]float32)
case float64:
tempMap[dataName+fmt.Sprint(index)] = item.(float64)
case []float64:
tempMap[dataName+fmt.Sprint(index)] = item.([]float64)
case string:
tempMap[dataName+fmt.Sprint(index)] = item.(string)
case []string:
tempMap[dataName+fmt.Sprint(index)] = item.([]string)
/* Marshalling problem occurs, So the follwing is commented */
/* json: unsupported type: complex64 */
/* json: unsupported type: complex128 */
/*
case complex64:
tempMap[dataName+fmt.Sprint(index)] = item.(complex64)
case complex128:
tempMap[dataName+fmt.Sprint(index)] = item.(complex128)
case []complex64:
tempMap[dataName+fmt.Sprint(index)] = item.([]complex64)
case []complex128:
tempMap[dataName+fmt.Sprint(index)] = item.([]complex128)
*/
default:
fmt.Println("Got ", t)
panic("An illegal data value")
}
}
node.Record = tempMap
/* node.next = nil */
return &node
}