-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlinked_list_ex
More file actions
executable file
·54 lines (43 loc) · 1.01 KB
/
linked_list_ex
File metadata and controls
executable file
·54 lines (43 loc) · 1.01 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
#!/bin/bash
#
# Linked list implementation (nobody should need to do this ;).
readonly DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
. ${DIR}/../gobash
function Node() {
make_ $FUNCNAME \
"val" "${1}" \
"next" "${2}"
}
function Node_to_string() {
local -r node="${1}"
shift 1 || return $EC
printf "$($node val)"
}
function LL() {
make_ $FUNCNAME \
"head" "$NULL" \
"size" 0
}
function LL_add() {
local -r ll="${1}"
local -r val="${2}"
shift 2 || return $EC
local -r node=$(Node "$val" "$($ll head)")
$ll head "$node"
$ll size $(( $($ll size) + 1 ))
}
function LL_to_string() {
local -r ll="${1}"
shift 1 || return $EC
local c=$($ll head)
while [ "$c" != "$NULL" ]; do
$c to_string
printf " -> "
c=$($c next)
done
printf "null \n"
}
ll=$(LL)
$ll add 3
$ll add 5
$ll to_string