什么叫做插入排序!
{
if (s[in]>s[in+1])
{
swap(in,in+1);
}
}
}
for (int j =0;j< a;j++)
{
System.out.println(j+"="+s[j]);
}
}
private void swap(int one ,int two)
{
int temp = s[one];
s[one] = s[two];
s[two] = temp;
}
public static void main(String[] args)
{
Sort in = new Sort();
//in.insort();
in.selectSort();
// in.bubbleSort();
}
}
4、快速排序
先取数组的中间元素,并将数组分为两个较小的数组,其中一个数组只含大于这个中间值的元素,而另一个数组只含小于这个中间值的元素,重复这一过程。
public class arrayQsort{
static void qsort(int array[],int first,int last){
int low=first;
int high=last;
if(first>=last) return;
int mid=array[(first+last)/2];
do{
while(array[low]< mid)
low++;
while(array[high]>mid)
high--;
if(low<=high){
int temp=array[low];
array[low++]=array[high];
array[high--]=temp;
}
}while(low<=high);
qsort(array,first,high);
qsort(array,low,last);
}
public static void main(String[] args){
int[] s = {12,4,56,44,3,34,32,2,5,21};
qsort(s,0,9);
for (int j =0;j<10;j++)
{
System.out.println(j+"="+s[j]);
}
}
}
程序运行的一个结果:
参与评论- 相关内容
- 最近更新
- ·c 编q-m算法
- ·数据结构课程设计
- ·索爱W958性价比
- ·O2 XDA Atom 手机的性能
- ·哪里可以下载手机上Txt的歌词
- ·N73最新软件版本?那个好?
- ·N73存储卡上装的内容多会影响机器..
- ·三星E908输入哪几个字符能查通话..
- ·A780刷机文件
- ·QQ留言出现问题,窗口自动关闭
添加到百度搜藏