C# 数组冒泡排序复习
程序员文章站
2022-06-13 17:33:29
using System; namespace runoob { class MyClass { static void Main(string[] args) { MyClass1 myClass = new MyClass1(); myClass.Dialog(); } } class MyCl ......
using system; namespace runoob { class myclass { static void main(string[] args) { myclass1 myclass = new myclass1(); myclass.dialog(); } } class myclass1 { public void dialog() { console.writeline("请输入要产生的随机数的个数"); int num = convert.toint32(console.readline()); int[] array = new int[num]; random random = new random(); for (int i = 0; i <= num - 1; i++) { array[i] = random.next(0, 100); } console.writeline("您输入的数是:"); foreach (var arr in array) { console.write(arr + " "); } for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (array[i] < array[j]) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } } } console.writeline(); console.writeline("您输入的数从大到小排序是:"); foreach (var item in array) { console.write("{0}\t", item); } for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (array[i] > array[j]) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } } } console.writeline(); console.writeline("您输入的数从小到大排序是:"); foreach (var item1 in array) { console.write("{0}\t", item1); } } } }
上一篇: Docker堆栈的管理操作详解
下一篇: 财神:如何赚更多的钱