selectionsort.java

来自「包括了5个基本排序过程」· Java 代码 · 共 52 行

JAVA
52
字号

public class SelectionSort //选择
{
	private double[] unsorted;
	private double[] sorted;
	public SelectionSort()
	{
	}
	public SelectionSort(double[] temp)
	{
		setdata(temp);
		sort();
	}
	public void setdata(double[] temp)
	{
		unsorted=new double[temp.length];
		sorted=new double[temp.length];
		for(int i=0;i<temp.length;i++)
			{
				sorted[i]=unsorted[i]=temp[i];
				//System.out.println(sorted[i]);
			}
	}
	public void sort()
	{
		int n=sorted.length;
		double temp=sorted[0];
		int tar=0;
		while(n>1)
		{			
			temp=sorted[0];
			tar=0;
			for(int j=0;j<n;j++)
			{
				if(sorted[j]>temp)
					{
						temp=sorted[j];
						tar=j;
					}
			}
			n--;
			sorted[tar]=sorted[n];
			sorted[n]=temp;
		}
	}
	public double[] getresult()
	{
		return sorted;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?