- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace c4._3
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] num = new int[10];
- Program p=new Program();
- Console.WriteLine("原始数组:");
- p.randIt(num);
- p.show(num);
- p.sort(num);
- Console.WriteLine();
- Console.WriteLine("降序数组");
- p.show(num);
- Console.ReadKey();
- }
- public void randIt(int[] num)
- {
- Random randNum = new Random();
- for (int i = 0; i < num.Length; i++)
- {
- num[i]= randNum.Next(101);//101??
- }
- }
- //这是冒泡的算法
- public void sort(int[] arr)
- {
- for(int i=0;i<arr.Length;i++)
- for (int j = 0; j < arr.Length-i-1; j++)//看清楚j的终止条件
- {
- if (arr[j]< arr[j+1])
- {
- int temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j +1] = temp;
- }
- }
- }
- public void show(int[] arr)
- {
- foreach (int i in arr)
- {
- Console.Write("{0} ", i);
- }
- }
- }
- }