forked from kiba518/CSharpClassicProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
利用列表排n个数的序.txt
36 lines (36 loc) · 903 Bytes
/
利用列表排n个数的序.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections ;
class ArraySort
{
static void Main()
{
ArrayList myArrayList=new ArrayList ();
Console.WriteLine ("你想排几个数的序:");
int iNumber=int.Parse (Console.ReadLine ());
for(int i=1;i<=iNumber;i++)
{
Console.WriteLine ("请输入第{0}个数:",i);
int temp=int.Parse (Console.ReadLine ());
myArrayList.Add (temp);
}
Console.WriteLine ("\n排序前的内容:");
ArraySort myArraySort=new ArraySort ();
myArraySort.WriteList (myArrayList);
myArrayList.Sort ();
Console.WriteLine ("\n逆序后的内容:");
myArraySort.WriteList (myArrayList);
myArrayList.Reverse ();
Console.WriteLine ("\n正序后的内容:");
myArraySort.WriteList (myArrayList);
}
void WriteList(ArrayList myArrayList)
{
Console.WriteLine ();
int pSize=myArrayList.Count;
for(int i=0;i<pSize;i++)
{
Console.Write (myArrayList[i]+"\t");
}
Console.WriteLine ();
}
}