初学C#写了一段排序代码 各位看看到底算是冒泡还是选择
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
int inumber;
string strchoice;
Console.WriteLine("type in the number of the numbers you want");
inumber = Int32.Parse(Console.ReadLine());
fh();
px(inumber);
fh();
do
{
Console.WriteLine("again");
Console.WriteLine("press y to continue");
strchoice = Console.ReadLine();
if (strchoice == "y" || strchoice == "Y")
{
Console.WriteLine("type in the number of the numbers you want");
inumber = Int32.Parse(Console.ReadLine());
fh();
px(inumber);
fh();
}
else
break;
}
while (strchoice != "y" || strchoice!="Y");
Console.WriteLine("press any key to exit");
}
static void px(int j)
{//赋值
int imin;
int itemp;
int[] ainumber = new int[j];
for (int i = 0; i < ainumber.Length; i++)
{
Console.WriteLine("type in the number you want");
ainumber[i] = Int32.Parse(Console.ReadLine());
}
//排序
for (int i = 0; i < j; i++)
{
imin = i;
itemp = ainumber[i];
for (int k = i+1; k < j; k++)
{
if (ainumber[imin] > ainumber[k])
{
itemp = ainumber[imin];
ainumber[imin] = ainumber[k];
ainumber[k] = itemp;
}
}
}
fh();
for (int i = 0; i < ainumber.Length; i++)
{
Console.WriteLine(ainumber[i]);
}
fh();
}
static void fh()
{
Console.WriteLine("*******************************************************");
}
}
}
写实照着选择排序的算法来的 后来看看觉得好像是冒泡了~
PS,写完这段正在写插入排序了 没有头绪 有没有哪位高手给点指导啊