充分發揮多核威力的排序法 sleep sort
程式(sleepsort.bash):
while [ -n "$1" ]
do
(sleep "$1"; echo "$1") &
shift
done
wait
執行例:
user@your-c24a217e1d ~
$ bash sleepsort.bash 4 1 3
1
3
4
user@your-c24a217e1d ~
$ bash sleepsort.bash 4 2 5 1 3
1
2
3
4
5
while [ -n "$1" ]
do
(sleep "$1"; echo "$1") &
shift
done
wait
執行例:
user@your-c24a217e1d ~
$ bash sleepsort.bash 4 1 3
1
3
4
user@your-c24a217e1d ~
$ bash sleepsort.bash 4 2 5 1 3
1
2
3
4
5
留言
張貼留言