- int[] numbers = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
- for (int i = 0; i < numbers.Length - 1; i++)
- {
- for (int j = 0; j < numbers.Length - 1 - i; j++)
- {
- if (numbers[j] > numbers[j + 1])
- {
- int temp = numbers[j];
- numbers[j] = numbers[j + 1];
- numbers[j + 1] = temp;
- }
- }
- }
- for (int i = 0; i < numbers.Length; i++)
- {
- Console.WriteLine(numbers[i]);
- }
- Console.ReadKey();
复制代码 这是我们学的冒泡排序,老师说是面试必须有的面试题,但今天听同学说还有 优化的冒泡排序 ???那个怎么写啊?????
|
|