C 氣泡排序

2021-09-21 06:01:52 字數 1074 閱讀 5740

氣泡排序,helper幫助類,裡面寫一了乙個給int陣列排序的的非靜態方法,然後將排序好的陣列返回。

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace sorthelper

int length = intarray.length;

int temp = 0;

for (int i = 0; i < length - 1; i++)//氣泡排序,兩兩比較,小的在前,大的在後}}

array = intarray;

return array;}}

}

在main方法中呼叫該排序方法……

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace sorthelper

; bubblesorthelper bsh = new bubblesorthelper();

int result = bsh.bubblesortintarray(testarray);

stringbuilder sb = new stringbuilder();

for (int i = 0; i < result.count(); i++)

sb.remove(sb.length - 1,1);

console.writeline(sb);

console.readline();}}

}

執行結果:

氣泡排序

C 氣泡排序

using system using system.collections.generic using system.linq using system.text 個數是 j 1 num j double.parse console.readline console.writeline 你剛才輸入的...

C 氣泡排序

class program endregion region 該方法獲得需要排序的陣列,表呼叫排序方法進行排序 該方法獲得需要排序的陣列,表呼叫排序方法進行排序 public static void sortednumbers 個數字 numbercount for int i 0 i number...

氣泡排序 C

氣泡排序 1 排序方法 將被排序的記錄陣列r 1.n 垂直排列,每個記錄r i 看作是重量為r i key的氣泡。根據輕氣泡不能在重氣泡之下的原則,從下往上掃瞄陣列r 凡掃瞄到違反本原則的輕氣泡,就使其向上 飄浮 如此反覆進行,直到最後任何兩個氣泡都是輕者在上,重者在下為止。1 初始 r 1.n 為...