写写java玩玩

justxd 2007-09-21 05:40:42

public class Compositor {

/********************************************************/
/* 快速排序法(QuickSort) */
/* Author:Carl */
/* Create Date:09/21/2007 */
/********************************************************/
public int[] QuickSort(int[] array) {

Sort(array,0,array.length-1);
return array;
}

private void Sort(int[] array ,int low,int height)
{
int pviotpos;
if(low<height)
{
pviotpos=Partition(array,low,height);
Sort(array,low,pviotpos-1);
Sort(array,pviotpos+1,height);
}
}

private int Partition(int[] array,int i,int j)
{

int pivot =array[i];
while(i<j)
{
while(i<j&&array[j]>=pivot)
j--;

if(i<j)
array[i++]=array[j];

while(i<j &&array[i]<=pivot)
i++;
if(i<j)
array[j--]=array[i];
}
array[i]=pivot;
return i;
}

/********************************************************/
/* 冒泡排序法(BubleSort) */
/* Author:Carl */
/* Create Date:09/21/2007 */
/********************************************************/
public int[] BubbleSort(int[] array)
{
int i=0;
boolean flag=true;
while(i<array.length && flag)
{
int temp=0;
flag=false;
for(int j=0;j<array.length-i-1;j++)
{
if(array[j]>array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
flag=true;
}
}
i++;
}
return array;
}

/********************************************************/
/* 选择排序法(SimpleSelectSort) */
/* Author:Carl */
/* Create Date:09/21/2007 */
/********************************************************/
public int[] SimpleSelectSort(int[] array)
{
int i,j,k,temp;
for(i=0;i<array.length-1;i++)
{
k=i;
for(j=i+1;j<array.length;j++)
{
if(array[j]<array[k])
{
k=j;
}
}
if(k!=i)
{
temp=array[k];
array[k]=array[i];
array[i]=temp;
}
}
return array;

}

/********************************************************/
/* 插入排序法(InsertSort) */
/* Author:Carl */
/* Create Date:09/21/2007 */
/********************************************************/
public int[] InsertSort(int[] array)
{
int i,j,temp;
for(i=1;i<array.length;i++)
{
j=i-1;
temp=array[i];
while(j>=0&&temp<array[j])
{
array[j+1]=array[j];
j--;
}
array[j+1]=temp;
}
return array;
}

/********************************************************/
/* 二分排序法(BinarySort) */
/* Author:Carl */
/* Create Date:09/21/2007 */
/********************************************************/
public int[] BinarySort(int[] array)
{
int left,right,middle,i,j;
for(i=1;i<array.length;i++)
{
left=0;
right=i-1;
int pivot=array[i];

while(left<=right)
{
middle=(right+left)/2;
if(pivot>array[middle])
{
left=middle+1;
}else
{
right=middle-1;
}
}
for(j=i-1;j>=left;j--)
array[j+1]=array[j];

array[left]=pivot;
}
return array;
}
}


大哥们,小弟对java的基础有一点了解,想问问我接下来该怎么走?
...全文
90 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧