氣泡排序對字串陣列排序

2021-08-13 04:46:08 字數 657 閱讀 5480

給定乙個字串排序:以字母為準,比如:a < b或者b .同字母的情況,小寫字母大於大寫字母,比如:a < a

private

static

void

testcomparestring() ;

//使用do-while

boolean ischanged;

int nmaxindex = asource.length - 1;

string temp = null;

do }

nmaxindex--;//大的沉底,小的向上浮。開始是10-->0

}while(ischanged);

//方式2:使用for進行

/*for (int i = 0; i < asource.length - 1; i++)

}}*/

system.out.println("********************====");

for (int i = 0; i < asource.length; i++)

}private

static

intstringcmp(string s1, string s2) else }}

return diffnum;

}

C語言 陣列,字串陣列,氣泡排序

一 陣列 1.陣列的定義 intarr 或者 int arr 10 初始化元素的個數可以不全,未初始化的元素預設為0 2.求陣列的空間 sizeof arr 或者sizeof 元素 元素的個數 3.求陣列的個數 假設arr為int型別的陣列,sizeof arr sizeof int 或者sizeo...

對字串排序

def main 字串 s helloworld 轉換成陣列 l list s 對陣列排序,注意,該方法沒有返回值 l.sort 轉換成陣列 s join l print s 結果如下 hwdellloor if name main main 然後sort再join。def main s hello...

字串排序(氣泡排序法模擬)

氣泡排序排序多個字串 include include void compare sort char a,int sz void show char a,int sz int main int sz sizeof arr sizeof arr 0 計算陣列長度,這裡陣列長度為3 compare sor...