✔ 最佳答案
有個建議,用Node。Node的結構是
struct Node {
char* word;
Node* next;
};
首先讀取檔案前設定了一個長度是26的pointer array。
Node *aryAlpha[26];
然後每讀一個字串便依它的字母排列在指定的array位置。
在加入位置前以bubble sort模式校對字串尋找識當位置並且插入字串(如要求不高,可順次序比較和插入字串)。
最後,大概那個array內容如下:
aryAlpha[0] -> "apple" -> "apply" -> null
aryAlpha[1] -> "baby" -> "boy" -> null
aryAlpha[2] -> "cat" -> null
....
aryAlpha[25] -> "zoo" -> null
然後用for loop 列出每一個array的位置直至顯示該pointer指的是null。
for (i = 0; i < 26; i++) {
for (ptr = aryAlpha[i]; ptr != null; ptr = ptr ->prt.next) {
output(ptr->word);
}
}