二分法也叫快速排序法,是算法中几种排序思想最为复杂的一种,它的思想是在一组数据中找一个基准值,然后把所有大于这个基准值的数都放在这个基准值的右边,所有小于这个基准值的数都放在这个基准值的左边。然后将这个数据分成了两个小的数组,再从这两个小的数组中分别找一个基准值,对这两个小的数组再进行精分,依次类推,用到了函数中递归的思想,其整体思想与折半查找法也十分相似。
#include <stdio.h>
#include <string.h>
#define N 32 //关键字数量
#define M 20 //输入的单词数
#define LEN 10 //每个单词的最大长度
int InputWord(char s[][LEN]);
void OutputCountResults(char keywords[][LEN], int count[], int n);
int IsKeyword(char s[]);
void CountKeywords(char s[][LEN], int n);
int main(void)
{
//=======begin=======
//========end========
}
//函数功能:以回车符作为分隔符输入多个单词,以end作为结束
int InputWord(char s[][LEN])
{
//=======begin=======
//========end========
}
//函数功能:输出关键字统计结果
void OutputCountResults(char keywords[][LEN], int count[], int n)
{
//=======begin=======
//========end========
}
//函数功能:判断s是否是C语言关键字,若是,则返回其下标,否则返回-1
int IsKeyword(char s[])
{
char keywords[N][LEN] = {"auto", "break", "case", "char", "const",
"continue", "default", "do", "double","else",
"enum", "extern", "float", "for", "goto",
"if", "int", "long", "register", "return",
"short", "singed", "sizeof", "static",
"struct", "switch", "typedef", "union",
"unsigned", "void", "volatile", "while"
};//二维字符数组构造关键字词典
//=======begin=======
//========end========
}
//函数功能:统计二维字符数组s中关键字的数量存于结构体数组keywords的count成员中
void CountKeywords(char s[][LEN], int n)
{
char keywords[N][LEN] = {"auto", "break", "case", "char", "const",
"continue", "default", "do", "double","else",
"enum", "extern", "float", "for", "goto",
"if", "int", "long", "register", "return",
"short", "singed", "sizeof", "static",
"struct", "switch", "typedef", "union",
"unsigned", "void", "volatile", "while"
};//二维字符数组构造关键字词典
//=======begin=======
//========end========
}