shell脚本编程(快速排序)
来源:互联网 发布:淘宝总公司投诉电话 编辑:程序博客网 时间:2024/05/01 14:46
#!/bin/bash#shell脚本编程之快速排序的实现(以最右边为元点的思想)a=(8 5 10 3 2 93 4 1 2 3 40 9 61 8 6 29)#a=(0 0 0 0 1 2 3 3 4 4 8 28 30495 921 43716)temp=buff=#交换函数swap(){buff=${a[$1]}a[$1]=${a[$2]}a[$2]=$buff}fun(){i=$(($1-1))j=$1temp=${a[$2]}if test $1 -ge $2 ;thenreturn 2 fiwhile [ $j -le $2 ];do[ $j -lt $2 ] && while [[ ${a[$j]} -gt $temp ]] ;do j=$(($j+1))donei=$(($i+1))swap $i $jj=$(($j+1))done fun 0 $(($i-1)) fun $(($i+2)) $2}fun 0 15for((i=0;i<16;i++)){echo -n ${a[$i]} " "}echoexit 0
下面是C++快速排序的对照代码
#include <iostream>using namespace std;void swap(int *a,int *b){int temp = *a;*a = *b;*b = temp;}void Grial(int a[],int x,int y){int i=x-1;int j=x;if(x>=y)return;int temp = a[y];while(j<=y){while(j<y&&a[j]>a[y])j++;i++;swap(&a[i],&a[j]);j++;}Grial(a,0,i-1);Grial(a,i+1,y);}int main(){int a[]={4,3,921,30495,28,43716,3,4,0,0,2,0,0,1,8,5};Grial(a,0,14);for(int i=0;i<15;i++){cout<<a[i]<<" ";}cout<<endl;}
1 0
- shell脚本编程(快速排序)
- Shell脚本编程快速上手
- shell编程防火墙快速配置脚本
- shell脚本编程(合并排序)
- Shell脚本快速入门
- shell脚本实现shell排序
- 冒泡排序 shell 脚本
- 快速排序 shell实现
- shell 完成快速排序
- shell脚本排序(冒泡排序)
- Shell脚本编程-脚本格式
- SHELL脚本编程
- shell脚本编程
- Shell脚本编程-变量
- Shell脚本编程-引用
- SHELL 脚本编程
- linux脚本(shell)编程
- Shell脚本编程基础
- C#中枚举类型的使用
- Scala编程指南(3) 揭示Scala的本质
- 92. Reverse Linked List II
- 理解Certificate、App Id、Identifiers 和 Provisioning Profile
- metasploit - meterpreter commands (linux)
- shell脚本编程(快速排序)
- 15.精灵进阶之给节点添加动作
- R语言中的并行计算——二、搭建R的集群
- SQL Server 损坏修复
- LeetCode twoSum
- Java垃圾回收是如何工作的?
- Objective-C - 模型的设计
- Distinctive Image Features from Scale-Invariant Keypoints-SIFT算法译文
- Android环境搭建 目录介绍