复制可直接用 java
public class Test {
public static void main(String args[])
{
//定义数组
int num[]={1,2,5,34,12,4,12,7,37,88};
for(int i=0;i
for(int j=0;j
//用第一个数和第二个数比较,大的往上浮,小的往下沉
//再用第二个数和第一个数比较,同理....依次类推
if(num[j]
num[j]=num[j]+num[j+1];
num[j+1]=num[j]-num[j+1];
num[j]=num[j]-num[j+1];
}
}
}
for(int m=0;m
System.out.println(num[m]);
}
}
}
用冒泡排序的方法可以实现,两个For循环,实例如下:
static void Main(string[] args)
{
int[] a = { 12, 22, 1, 5, 21, 123, 8, 6, 90, 11 };
int temp;
for (int i = 0; i < a.Length; i++)
{
for (int j = i; j < a.Length; j++)
{
if (a[i] > a[j])
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
for (int i = 0; i < a.Length; i++)
{
Console.Write(a[i] + "\n");
}
Console.ReadLine();
}
using System;
namespace ConsoleApplication1
{
///
/// Class1 的摘要说明。
///
class Class1
{
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main(string[] args)
{
MinToMax mtm = new MinToMax();
int[] array = { 1, 2, 6, 3, 8, 3, 4, 0, 5, 23, 52, 12, 234, 235, 1232, 21, 234, 123, 143, 1368 };
int[] last = mtm.MTM(array);
int n = 0;
for (int i = 0; i < array.Length; i++)
{
System.Console.Write(last[i] + "<");
++n;
}
System.Console.WriteLine("\n总共{0}个数字", n);
System.Console.ReadLine();
//
// TODO: 在此处添加代码以启动应用程序
//
}
}
public class MinToMax
{
public int[] MTM(int[] array)
{
int[] FianlMTM = new int[array.Length];
for (int j = 0; j < array.Length; j++)
{
int last = 0;
for (int i = 1; i < array.Length - j; i++)
{
int t = array[i];
if ((array[i]) < (array[i - 1]))
{
array[i] = array[i - 1];
last = array[i];
array[i - 1] = t;
}
else
last = array[i];
}
FianlMTM[array.Length - (j + 1)] = last;
}
return FianlMTM;
}
}
}
///冒泡排序 bubble sorting
int t;
int[] a ={150,56,20,94,97,123};
for(int j =a.Length-1;j>0;j--)
{
for(int i =0;i
if(a[i]>a[i+1])
{
t =a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
for(int u =0;u