Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Stack/UNIX-Shell/stack-2.sh
Normal file
32
Task/Stack/UNIX-Shell/stack-2.sh
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
init_stack() {
|
||||
if [[ -n $KSH_VERSION ]]; then
|
||||
eval 'set -A '"$1"
|
||||
else
|
||||
eval "$1=()"
|
||||
fi
|
||||
}
|
||||
|
||||
push() {
|
||||
eval "$1"'=("$2" "${'"$1"'[@]}")'
|
||||
}
|
||||
|
||||
stack_top() {
|
||||
eval 'set -- "${'"$1"'[@]}"';
|
||||
printf '%s\n' "$1"
|
||||
}
|
||||
|
||||
pop() {
|
||||
stack_top "$1";
|
||||
eval "$1"'=("${'"$1"'[@]:1}")'
|
||||
}
|
||||
|
||||
empty() {
|
||||
eval '(( ${#'"$1"'[@]} == 0 ))'
|
||||
}
|
||||
|
||||
init_stack mystack
|
||||
push mystack fred; push mystack wilma; push mystack betty; push mystack barney
|
||||
printf 'peek(mystack)==%s\n' "$(stack_top mystack)"
|
||||
while ! empty mystack; do
|
||||
pop mystack
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue