卸载kernel玩一玩
废话不多说,下面开始卸载内核这一惊险之旅,特别提醒在开始之前做好虚拟机的快照,也许会造成系统无法启动,也许会出现各种错误,也许会笑着删数据库跑路,也许会从入门到放弃,,请系好安全带。
练习
冒泡排序法
#!/bin/bash
#
#Author:jasonmc
#Date:2016-08-24
#Description:buble sort.
#
NUM_FILE=./random.txt #get number from file
#########################################################
swap_element(){
local tmp=0
tmp=${NUM_SEQUENCE[$1]}
NUM_SEQUENCE[$1]=${NUM_SEQUENCE[$2]}
NUM_SEQUENCE[$2]=$tmp
}
show_element(){
echo "${NUM_SEQUENCE[*]},swap $swap_count times"
}
#########################################################
#
#The original bubble sort.
bubble_sort_orgi(){
for ((i=0;i<${#NUM_SEQUENCE[*]}-1;i++))
do
for ((j=0;j<${#NUM_SEQUENCE[@]}-i-1;j++))
do
if [ ${NUM_SEQUENCE[$j]} $1 ${NUM_SEQUENCE[$[j+1]]} ]
then
swap_element $j $[j+1]
let swap_count++
fi
done
done
}
#Use the original bubble sort,by increase
NUM_SEQUENCE=(`cat $NUM_FILE`)
bubble_sort_orgi -gt
show_element
#Use the original bubble sort,by decrease
NUM_SEQUENCE=(`cat $NUM_FILE`)
swap_count=0
bubble_sort_orgi -lt
show_element
#
#With a flag to mark the sequence,if the sequence has been order,stop
bubble_sort_flag(){
flag=0
for ((i=0;i<${#NUM_SEQUENCE[@]}-1,!flag;i++))
do
flag=1
for ((j=0;j<${#NUM_SEQUENCE[*]}-i-1;j++))
do
if [ ${NUM_SEQUENCE[$j]} $1 ${NUM_SEQUENCE[$[j+1]]} ]
then
swap_element $j $[j+1]
flag=0
let swap_count++
fi
done
done
}
#bubble with flag.
NUM_SEQUENCE=(`cat $NUM_FILE`)
swap_count=0
bubble_sort_flag -gt
show_element
#
NUM_SEQUENCE=(`cat $NUM_FILE`)
swap_count=0
bubble_sort_flag -lt
show_element
#
#Record the last position of bubble sort
bubble_sort_last(){
current=0
last=$[${#NUM_SEQUENCE[*]}-1]
while [ $last -gt 0 ]
do
for ((i=current=0;i<last;i++))
do
if [ ${NUM_SEQUENCE[$i]} $1 ${NUM_SEQUENCE[$[i+1]]} ]
then
swap_element $i $[i+1]
current=$i
let swap_count++
fi
done
last=$current
done
}
#
#Record last order position.
NUM_SEQUENCE=(`cat $NUM_FILE`)
swap_count=0
bubble_sort_last -gt
show_element
#
NUM_SEQUENCE=(`cat $NUM_FILE`)
swap_count=0
bubble_sort_last -lt
show_element
#
#Bidirectional bubble sort
bubble_sort_bid(){
head=0
tail=$[${#NUM_SEQUENCE[*]}-1]
while [ $head -lt $tail ]
do
for ((i=head;i<tail;i++))
do
if [ ${NUM_SEQUENCE[$i]} $1 ${NUM_SEQUENCE[$[i+1]]} ]
then
swap_element $i $[i+1]
index=$i
let swap_count++
fi
done
tail=$index
for ((i=tail;i>head;i--))
do
if [ ! ${NUM_SEQUENCE[$i]} $1 ${NUM_SEQUENCE[$[i-1]]} ]
then
swap_element $i $[i-1]
index=$i
let swap_count++
fi
done
head=$index
done
}
#
#increase
NUM_SEQUENCE=(`cat $NUM_FILE`)
swap_count=0
bubble_sort_bid -gt
show_element
#
#decrease
NUM_SEQUENCE=(`cat $NUM_FILE`)
swap_count=0
bubble_sort_bid -lt
show_element
#
unset i j index head tail NUM_FILE NUM_SEQUENCE swap_count last tmp flag
原创文章,作者:helloc,如若转载,请注明出处:http://www.178linux.com/40304