#include <bits/stdc++.h>
#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10 //线性表存储空间的分配增量
int n;
typedef struct {
char word[21]; //存储单词,不超过 20 个字符
int count; //单词出现的次数
} ElemType;
typedef struct Node {
ElemType *elem; //存储空间基址
int length; //当前长度
int listsize; //当前分配的存储容量
} Node;
typedef struct Node SqList;
void InitList(SqList &L) {
L.elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem) {
printf("初始化空间失败");
exit(OVERFLOW);
}
L.length=0;
L.listsize=LIST_INIT_SIZE;
}
int LocateElem(SqList &L,char *s) {
if(L.length==0) return -1;
for(int i=1; i<=L.length; i++) {
if(strcmp(L.elem[i].word,s)==0) {
L.elem[i].count++;
return 0;
}
if(strcmp(L.elem[i].word,s)>0) {
return i;
}
}
}
void InsertList(SqList &L,int i,char *s) {//i为待插入位置
if(i>L.length+1) {
printf("插入字符串%s失败\
文本文件单词统计
最新推荐文章于 2023-12-27 15:46:37 发布