Last active
January 21, 2017 05:05
-
-
Save don-han/6d118888ca837156989d to your computer and use it in GitHub Desktop.
My attempt at implementing Queue data structure in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
push_queue(){ | |
element_to_store="$1" | |
queue+=($element_to_store) | |
} | |
pop_queue(){ | |
args=${queue[0]} | |
queue=("${queue[@]:1}") | |
} | |
declare -a queue | |
echo ${queue[@]} # | |
push_queue "one" | |
echo ${queue[@]} # one | |
push_queue "two" | |
echo ${queue[@]} # one two | |
pop_queue | |
echo ${queue[@]} # two | |
push_queue "three" | |
echo ${queue[@]} # two three | |
pop_queue | |
echo ${queue[@]} # three | |
pop_queue | |
echo ${queue[@]} # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment