Javaバブル法ソート例

1074 ワード

public class TestBubbleUp {

/* */
public static int[] sort(int[] m)
{
int theLenth = m.length;
/* theLenth */
for (int i = 0; i < theLenth; i++)
{
/* , */
for (int j = 0; j < theLenth - i - 1; j++)
{
int a = m[j];
int b = m[j + 1];
if (a < b)
{
m[j] = b;
m[j + 1] = a;
}
}
}
return m;
}

public static void main(String args[])
{
int[] m =
{ 0, 1, 9, 13, 27, 39, 88, 100 };
int[] n = sort(m);
for (int i = 0; i < m.length; i++)
{
System.out.println(n[i] + "/n");
}
}
}