C語言 寫氣泡排序可以排序多個字串。

2021-08-25 12:00:46 字數 522 閱讀 7306

此題的解決思路為:首先整體思路為氣泡排序法,其次它是要排序多個字串,這裡就要用到字串的比較strcmp,通過判斷比較兩字串然後再進行交換排序。

具體**如下:

#include 

#include

#include

void bubble_str(char *arr, int sz)}}

}int main()

; int i = 0;

int sz = sizeof(arr) / sizeof(arr[0]);

for (i = 0; i < sz; i++)//列印原多個字串

bubble_str(arr,sz);

printf("\n");

for (i = 0; i < sz; i++)//列印排序後的多個字串

system("pause");

return

0;}

C語言 氣泡排序排序多個字串

strcmp函式 原型 extern int strcmp const char s1,const char s2 用法 include 功能 比較字串s1和s2。一般形式 strcmp 字串1,字串2 說明 當s1s2時,返回值 0 即 兩個字串自左向右逐個字元相比 按ascii值大小相比較 直到...

使用氣泡排序,排序多個字串

define crt secure no warnings 1 include include include int main char str 指標陣列,每乙個都是字元指標 int i 0 int j 0 int flag int size sizeof str sizeof str 0 for...

快速排序用C語言可以這麼寫

include include 將nums中的資料,進行快速排序 param nums 待排序的陣列 param start 陣列中待排序序列的起始位置 param end 陣列中待排序序列的終止位置 void fastsort int nums,int start,int end 將樞紐元素歸位 ...