写写java玩玩

justxd justxd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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的基础有一点了解,想问问我接下来该怎么走?
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
justxd
J2ME 13,096 成员 26,491 内容