生活随笔
收集整理的這篇文章主要介紹了
数据结构源码笔记(C语言):英文单词按字典序排序的基数排序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<stdio.h>
#include<malloc.h>
#include<string.h>#define MaxLen 9
#define Radix 27typedef char String
[MaxLen
+1];typedef struct node
{String word
;struct node
*next
;
}LinkNode
;void DispWord(String r
[],int n
)
{int i
;printf(" ");for(i
=0;i
<n
;i
++)printf("[%s]",r
[i
]);printf("\n");
}void PreProcess(String r
[],int n
)
{int i
,j
;for(i
=0;i
<n
;i
++){if(strlen(r
[i
])<MaxLen
){for(j
=strlen(r
[i
]);j
<MaxLen
;j
++)r
[i
][j
]=' ';r
[i
][j
]='\0';}}
}void EndProcess(String r
[],int n
)
{int i
,j
;for(i
=0;i
<n
;i
++){for(j
=MaxLen
-1;r
[i
][j
]==' ';j
--);r
[i
][j
+1]='\0';}
}void Distribute(String r
[],LinkNode
*head
[],LinkNode
*tail
[],int j
,int n
)
{int i
,k
;LinkNode
*p
;for(i
=0;i
<n
;i
++){if(r
[i
][j
]=' ')k
=0;elsek
=r
[i
][j
]-'a'+1;p
=(LinkNode
*)malloc(sizeof(LinkNode
));strcpy(p
->word
,r
[i
]);p
->next
=NULL;if(head
[k
]==NULL){head
[k
]=p
;tail
[k
]=p
;}else{tail
[k
]->next
=p
;tail
[k
]=p
;}}
}void Collect(String r
[],LinkNode
*head
[])
{int k
=0,i
;LinkNode
*p
;for(i
=0;i
<Radix
;i
++)for(p
=head
[i
];p
!=NULL;p
=p
->next
)strcpy(r
[k
++],p
->word
);
}void RadixSort(String r
[],int n
)
{LinkNode
*head
[Radix
],*tail
[Radix
];int i
,j
;for(i
=MaxLen
-1;i
>=0;i
--){for(j
=0;j
<Radix
;j
++)head
[j
]=tail
[j
]=NULL;Distribute(r
,head
,tail
,i
,n
);Collect(r
,head
);}
}int main()
{int n
=6;String r
[]={"while","if","if-else","do-while","for","case"}; printf("排序前:\n"); DispWord(r
,n
);PreProcess(r
,n
);printf("預處理后:\n"); DispWord(r
,n
);RadixSort(r
,n
);printf("排序結果:\n"); DispWord(r
,n
);EndProcess(r
,n
);printf("最終結果:\n"); DispWord(r
,n
); return 0;
}
數據結構源碼筆記(C語言描述)匯總:
數據結構源碼筆記(C語言):英文單詞按字典序排序的基數排序
數據結構源碼筆記(C語言):直接插入排序
數據結構源碼筆記(C語言):直接選擇排序
數據結構源碼筆記(C語言):置換-選擇算法
數據結構源碼筆記(C語言):Huffman樹字符編碼
數據結構源碼筆記(C語言):Josephus問題之順序表
數據結構源碼筆記(C語言):Josephus問題之循環鏈接表
數據結構源碼筆記(C語言):多項式合并
數據結構源碼筆記(C語言):二叉樹之葉子結點旋轉銷毀
數據結構源碼筆記(C語言):哈夫曼樹
數據結構源碼筆記(C語言):集合的位向量表示
數據結構源碼筆記(C語言):鏈接隊列
數據結構源碼筆記(C語言):鏈接棧
數據結構源碼筆記(C語言):線性表的單鏈表示
數據結構源碼筆記(C語言):線性表的順序表示
數據結構源碼筆記(C語言):棧的基本操作
數據結構源碼筆記(C語言):中綴表達式
數據結構源碼筆記(C語言):希爾插入排序
數據結構源碼筆記(C語言):索引文件建立和查找
數據結構源碼筆記(C語言):冒泡排序
數據結構源碼筆記(C語言):快速排序
數據結構源碼筆記(C語言):可變長度字符串的快速排序
數據結構源碼筆記(C語言):基數排序
數據結構源碼筆記(C語言):二路歸并排序
數據結構源碼筆記(C語言):堆排序
數據結構源碼筆記(C語言):二叉樹搜索樹Kruskal
數據結構源碼筆記(C語言):二叉搜索樹Prim
數據結構源碼筆記(C語言):最短路徑弗洛伊德算法
數據結構源碼筆記(C語言):深度、廣度優先生成樹
數據結構源碼筆記(C語言):鄰接矩陣轉化鄰接表
數據結構源碼筆記(C語言):統計字符串中出現的字符及其次數
數據結構源碼筆記(C語言):順序查找
數據結構源碼筆記(C語言):哈希表的相關運算算法
數據結構源碼筆記(C語言):分塊法查找
數據結構源碼筆記(C語言):二分查找
數據結構源碼筆記(C語言):二叉樹遍歷
數據結構源碼筆記(C語言):二叉平衡樹的相關操作算法
數據結構源碼筆記(C語言):二叉排序樹的基本操作算法
數據結構源碼筆記(C語言):B樹的相關運算算法
總結
以上是生活随笔為你收集整理的数据结构源码笔记(C语言):英文单词按字典序排序的基数排序的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。