實現按指定字母序進行排序

2021-07-09 13:58:12 字數 1256 閱讀 3492

給定 n 個字串:abc dca add ae…

最終排序結果為:abc ae add dca

#include #include #include #include char need_arr = "abcdefghijklmnopqrstuvwxyz";

typedef char *words;

words *wordarr; //wordarr中存放分割完成的字串

int arrsize = 0;; //分割完成的字串的個數

#define maxwords 1000 //wordarr能存放的字串最大值

#define maxwordslen 20 //字串的最大長度

//字串分割

bool splitstr(char *str)

int i = 0;

wordarr = (char**)malloc(sizeof(words) * maxwords);

char *s = strtok(str, " ");

while(s != null)

arrsize = i;

return true;

}static int position(char *str, char c)

return (tmp - str) / sizeof(char);

}//根據自己制定的字串順序表比較字串的大小

int comstr(char *str1, char *str2)

else if((position(need_arr, *(str1+i))) < (position(need_arr, str2[i])))

else

i++;

} if(result == 0)

else if(strlen(str1) < strlen(str2))

}}//交換字串,小的字串放前面

int switchstr(char **str1, char **str2)

return 0;

}//氣泡排序

int sort_word(words *words)

{ int i;

int j;

for(i=0; i

執行結果:

SqlServer按指定順序進行排序

sql一 select from tabname where1 1order by charindex rtrim cast 列名 as nchar 北京,上海,廣州 sql二 select from tabname where id in 1 2,3 4,5 order by charindex ...

按字母順序對文字行進行排序

指標陣列的應用 include include define maxlines 5000 char lineptr maxlines char linestor int readlines char lineptr,int maxlines void writelines char lineptr,...

wepy 城市按字母排序

好吧,我不跟網上的人一樣 之貼出 也沒有資料結構,我很煩這樣的 所以我先貼一下資料結構 下圖是沒有修改的,直接從後台請求回的資料 下圖是經過修改後的資料 在block 因為後面我還需要多個view來用 所以就直接加了乙個block,如果你就乙個view就不用寫了 裡面寫好你需要渲染的資料列表,其中想...