数据结构课程设计 文章编辑 源代码
数据结构课设报告规范 数据结构课设 Python课程设计 源代码 实验报告 源码 世界杯查询系统

Ssize=0;
}
~lnkStack(){
clear();
}
void clear(){
while(top!=NULL){
Link<T> *tmp=top;
top=top->next;
delete tmp;
}
Ssize=0;
}
bool SisEmpty(){
if(Ssize==0)
return true;
世界杯查询系统
一.【需求分析】
1.输入
1.1.1输入来自3个文本文件.
1.1.2c.txt用于输出比赛的详细信息,如两队的队名,比分,进球球员姓名,进球时间等。
1.1.3file.txt用于输出对阵时间表。
1.1.4射手榜存档.txt用于存放进球球员的信息(姓名,国籍,进球数初始均设为1)。
2.输出
{
// TODO: Add your control notification handler code here
int point1;//比赛国家1比分
int point2;//比赛国家2比分
lnkList<xinxi> jinqiu;//比赛详细比分存入队列名为jinjiu,类定义为xinxi的队列中
};
2.1.2信息类
class xinxi{
public:
string time;
string country;
按下“某场比赛”则会在下方编辑框显示该场比赛的详细信息。
按下“射手榜”则会在下方编辑框显示该届世界杯结束后的射手榜。
按下“退出系统”则会清空编辑框以便下次输入。
二【数据结构设计】
数据结构课程设计报告含代码完整版

数据结构课程设计报告含代码HEN system office room 【HEN16H-HENS2AHENS8Q8-HENH1688】西安邮电学院数据结构课程设计报告题目:校园导航系统院系名称:计算机学院专业名称:计算机科学与技术班级:学生姓名:学号(8位):指导教师:设计起止时间:2011年12月11日~2011年12月15日一. 设计目的1.通过本次课程设计巩固《数据结构》中所学的内容;2.提高自己上机编程以及调试能力。
二. 设计内容1.设计所在学校的校园平面图,所含景点不少于10个。
以图中顶点表示校园内各景点,存放景点名称、代号、简介等信息;以边表示路径,存放路径长度等相关信息。
2.为来访客人提供图中任意景点相关信息的查询。
3.为来访客人提供图中任意景点的问路查询,即查询任意两个景点之间的一条最短的简单路径。
三.概要设计1.功能模块图;2.各个模块详细的功能描述。
1. 可以手动创建一个校园图。
2. 可以直接从文件读取校园各个景点的信息。
3. 可选择从任意个景点作为起点进行遍历。
4. 输入景点序号查询该景点相关信息。
5. 输入两个景点查询两个景点的最短,最佳及其所有的路径。
6. 将校园图信息保存入文件。
四.详细设计1.功能函数的调用关系图2.各功能函数的数据流程图1. Adjmatrix *g即结构体对象在main()中被创建在其他子函数中进行参数传递。
2. 全局变量visited数组中用。
3. 全局变量shorest[][],path[][]在floyd()中被赋值来分别记录v[i]-v[j]最短路径和 v[i]-v[j]所经过景点。
3.重点设计及编码两景点最短距离弗洛伊德算法void floyd(adjmatrix *g){int i,j,k;for(i=0;i<g->vexnum;i++)for(j=0;j<g->vexnum;j++)shortest[i][j]=0;for(i=0;i<g->vexnum;i++)for(j=0;j<g->vexnum;j++){shortest[i][j]=g->arcs[i][j].adj;path[i][j]=0;}for(i=0;i<g->vexnum;i++)for(j=0;j<g->vexnum;j++)for(k=0;k<g->vexnum;k++)if(shortest[i][j]>(shortest[i][k]+shortest[k][j])){shortest[i][j]=shortest[i][k]+shortest[k][j];path[i][j]=k;path[j][i]=k;}}五.测试数据及运行结果1.正常测试数据和运行结果要求提供3组正常测试数据和运行结果2(遍历功能)1(起始景点序号)1 校门呈长方形,校训:爱国、求实、奋进2 喷泉呈鸽子形状,喷射出水花3 教学楼传授知识和学习知识4 实验楼供学生进行课程实验和教师办公5 洗浴中心供学生洗澡,内设单人间和双人间6 美食广场仅一层,快餐味道不错7 图书馆共七层,存储大量书籍供学生查阅和学习8 旭日苑共三层,主要的就餐场所9 体育馆内设篮球场,羽毛球场和观看席10 宿舍休息的场所5(查询景点信息)2(景点序号)2 喷泉呈鸽子形状,喷射出水花6(查询两景点最短路径)1 9(两景点序号)1->2->7->91->9 最短距离:570米2.异常测试数据及运行结果要求提供2组异常测试数据和运行结果9无此功能模块请重新输入5(功能模块)11(景点序号)无此景点请重新输入六.调试情况,设计技巧及体会1.改进方案1. 可将景点文件,边文件及账户密码合并为一个文件。
数据结构课程设计报告模板(内附C代码)

数据结构课程设计报告学院专业:软件工程班级:学号:学生姓名:指导老师:彭伟民日期: 2016.01.01目录1猴子吃桃子问题 (3)1.1 需求分析 (3)1.2 程序设计思想 (3)1.3 程序源代码 (3)1.4 程序运行结果 (5)2进制数转化问题 (5)2.1 需求分析 (5)2.2 程序设计思想 (6)2.3 程序源代码 (6)2.4 程序运行结果 (7)3长整数运算 (8)3.1 需求分析 (8)3.2 程序设计思想 (8)3.3 程序源代码 (8)3.4 程序运行结果 (12)4学生成绩管理系统 (13)4.1 需求分析 (13)4.2 程序设计思想 (13)4.3 程序源代码 (14)4.4 程序运行结果 (20)5哈夫曼编码应用 (22)5.1 需求分析 (22)5.2 程序设计思想 (22)5.3 程序源代码 (23)5.4 程序运行结果 (24)6学校超市选址问题 (26)6.1 需求分析 (26)6.2 程序设计思想 (26)6.3 程序源代码 (26)6.4 程序运行结果 (30)7学生成绩管理系统 (30)7.1 需求分析 (30)7.2 程序设计思想 (30)7.3 程序源代码 (30)7.4 程序运行结果 (36)8排序综合 (37)8.1 需求分析 (37)8.2 程序设计思想 (38)8.3 程序源代码 (38)8.4 程序运行结果 (46)9课程设计总结 (47)1猴子吃桃子问题1.1需求分析有一群猴子摘了一堆桃子,他们每天都吃当前桃子的一半且再多吃一个,到了第10天就只余下一个桃子。
用多种方法实现求出原来这群猴子共摘了多少个桃子。
1.2程序设计思想已知第十天只余下1个桃子,第一天开始每天都吃当前桃子一半再多一个,那么就只需要从第十天开始倒推即可,用链表、数组、递推、常规方法都可以采用这种思路实现计算第一天桃子数量。
1.3程序源代码#include<iostream>using namespace std;//有一群猴子摘了一堆桃子,他们每天都吃当前桃子的一半且再多吃一个,到了第10天就只余下一个桃子。
数据结构课设(完整代码可直接运行)附注释

char adjvex;//最小生成树的节点
int lowcost;//到该节点的最小权值开销
}closedges[MAX_VERTEX_NUM];
int option; //图的类型标识符
int visited[MAX_VERTEX_NUM]; //顶点访问标记数组
for(i=1;i<=G.vexnum;++i) {//输入矩阵的各顶点
fflush(stdin); //清除缓存,略过
scanf("%c",&G.vexs[i]);
}//for
if(G.kind==DG||G.kind==UDG){//1.有向图和无向图的矩阵创建
for(i=1;i<=G.vexnum;i++)//矩阵初始化
if(!S.base) return ERROR;
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREAMENT;
}
*S.top++=e;
return OK;
}
/*·················元素出栈··········*/
int Pop(SqStack &S,int &e){
··········*/
int LocateVex(ALGraph G,char v){
int m;
for(m=1;m<=G.vexnum;m++){
if(G.vertices[m].data==v) return m;
}
printf("您输入的顶点不存在");
数据结构与算法课程设计源程序

程序:#include"stdio.h"#include"stdlib.h"#include "string.h"int saveflag=0;typedef struct LNode{ char id[20];//编号char name[10];//姓名char sex[10];//性别char age[10];//年龄char degree[10];//学位char position[10];//职位char phone[20];//电话char address[30];//住址struct LNode *next;}LNode,*Linklist;//定义节点类型int Initlist(Linklist &L){L=(Linklist)malloc(sizeof(LNode));if(!L)return (0);L->next=NULL;return 1;}//初始化单链表void Save(Linklist L){FILE* fp;LNode *p;int flag=1,count=0;fp=fopen("employee.txt","wb");if(fp==NULL){printf("\n=====>提示:重新打开文件时发生错误!\n");return;}p=L->next;while(p){if(fwrite(p,sizeof(LNode),1,fp)==1) //将第一个记录结点值写入文件{p=p->next; //依次写入第二个结点的值,count++; //文件的记录数+1}else{flag=0;break;}}printf("%d",count);if(count>0){printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count); saveflag=0;}else{system("cls");printf("保存文件失败,'0'条记录被保存!\n");}fclose(fp);}int CreatList(Linklist &L){Linklist p;p=(Linklist)malloc(sizeof(LNode));if(!p){return (0);}else{printf("请输入员工编号:");scanf(" %s",p->id);printf("请输入员工姓名:");scanf(" %s",p->name);printf("请输入员工性别:");scanf(" %s",p->sex);printf("请输入员工年龄:");scanf(" %s",p->age);printf("请输入员工学历:");scanf(" %s",p->degree);printf("请输入员工职务:");scanf(" %s",p->position);printf("请输入员工电话:");scanf(" %s",p->phone);printf("请输入员工地址:");scanf(" %s",p->address);}p->next=L->next;L->next=p;saveflag=1;return 1;}void Display(Linklist &L)//显示所有员工信息{Linklist p;printf("\n编号\t姓名\t性别\t年龄\t学历\t职位\t电话\t地址\n"); for(p=L->next;p!=NULL;p=p->next){printf("%s\t",p->id);printf("%s\t",p->name);printf("%s\t",p->sex);printf("%s\t",p->age);printf("%s\t",p->degree);printf("%s\t",p->position);printf("%s\t",p->phone);printf("%s\t",p->address);printf("\n");}}int SearchID(Linklist &L,char id[20])//ID查询{LNode *p;int flat=0;p=L;while(p){if(strcmp(p->id,id)==0){printf("查询结果如下:\n");printf("编号\t姓名\t性别\t年龄\t学历\t职位\t电话\t地址\n"); printf("%s\t",p->id);printf("%s\t",p->name);printf("%s\t",p->sex);printf("%s\t",p->age);printf("%s\t",p->degree);printf("%s\t",p->position);printf("%s\t",p->phone);printf("%s\t",p->address);flat=1;}p=p->next;}if(flat==0)printf("不存在此员工!\n");return 1;}int SearchName(Linklist &L,char name[10])//姓名查询{LNode *p;int flat=0;p=L;while(p){if(strcmp(p->name,name)==0){printf("查询结果如下:\n");printf("编号\t姓名\t性别\t年龄\t学历\t职位\t电话\t地址\n"); printf("%s\t",p->id);printf("%s\t",p->name);printf("%s\t",p->sex);printf("%s\t",p->age);printf("%s\t",p->degree);printf("%s\t",p->position);printf("%s\t",p->phone);printf("%s\t",p->address);flat=1;}p=p->next;}if(flat==0)printf("不存在此员工!\n");return 1;}void SortID(Linklist &L ,char id[20])//编号排序{Linklist La;Linklist p,q,m;La=(Linklist)malloc(sizeof(LNode));La->next =NULL;while(L->next){for(q=L->next,p=L->next;p->next;p=p->next ){if((strcmp( p->next->id,q->id ))>0 ){m=p;q=p->next ;}}if(q==L->next){L->next =L->next->next ;}else{m->next =q->next ;}q->next =La->next ;La->next =q ;}L=La;Display(L);}void SortName(Linklist &L ,char name[10])//姓名排序{Linklist La;Linklist p,q,m;La=(Linklist)malloc(sizeof(LNode));La->next=NULL;while(L->next){for(q=L->next ,p=L->next;p->next;p=p->next ){if((strcmp( p->next->name,q->name ))>0 ){m=p;q=p->next ;}}if(q==L->next){L->next=L->next->next ;}else{m->next=q->next ;}q->next=La->next ;La->next=q ;}L=La;Display(L);}void SortAge(Linklist &L ,char age[10])//年龄排序{Linklist La;Linklist p,q,m;La=(Linklist)malloc(sizeof(LNode));La->next =NULL;while(L->next){for(q=L->next ,p=L->next ;p->next;p=p->next ){if((strcmp( p->next->age,q->age))>0 ){m=p;q=p->next ;}}if(q==L->next){L->next=L->next->next ;}else{m->next=q->next ;}q->next=La->next ;La->next=q ;}L=La;Display(L);}void SortPhone(Linklist &L ,char phone[20])//电话排序{Linklist La;Linklist p,q,m;La=(Linklist)malloc(sizeof(LNode));La->next=NULL;while(L->next){for(q=L->next,p=L->next;p->next;p=p->next ){if((strcmp( p->next->phone,q->phone ))>0 ){m=p;q=p->next ;}}if(q==L->next){L->next=L->next->next ;}else{m->next=q->next ;}q->next=La->next ;La->next=q ;}L=La;Display(L);}int Updata(Linklist &L,char id[20])//更改{LNode *p;p=L;while(p){if(strcmp(p->id,id)==0){printf("请输入员工新编号(原来的编号:%s):\n",p->id);scanf("%s",p->id);printf("\n请输入员工新姓名(原来的姓名:%s):\n",p->name); scanf("%s",p->name);printf("\n请输入员工性别(原来的性别:%s):\n",p->sex); scanf("%s",p->sex);printf("\n请输入员工年龄(原来的年龄:%s):\n",p->age); scanf("%s",p->age);printf("\n请输入员工学历(原来的学历:%s):\n",p->degree); scanf("%s",p->degree);printf("\n请输入员工职务(原来的职务:%s):\n",p->position); scanf("%s",p->position);printf("\n请输入员工电话(原来的电话:%s):\n",p->phone); scanf("%s",p->phone);printf("\n请输入员工地址(原来的地址:%s):\n",p->address);scanf("%s",p->address);}p=p->next;}saveflag=1;return 1;}int Delete(Linklist &L,char id[20])//按ID删除{LNode *p;LNode *r;p=L->next;r=L;while(!(strcmp(p->id,id)==0)&&p){r=p;p=p->next;}if(!p)printf("\n删除位置不合理\n");else{r->next=p->next;free(p);printf("删除成功\n");}saveflag=1;return 1;}void menu(){printf(" **********************************************\n"); printf(" 欢迎进入员工管理系统!\n");printf(" **********************************************\n"); printf(" 1-添加员工信息\n");printf(" 2-查询员工信息\n");printf(" 3-排序员工信息\n");printf(" 4-显示所有员工信息\n");printf(" 5-更改员工信息\n");printf(" 6-删除员工信息\n");printf(" 7-退出\n");printf(" **********************************************\n"); }//主函数void main(){FILE *fp;Linklist L;LNode *p,*r;int a,count=0;char m,ch;char name[10];char id[20];char age[10];char phone[20];Initlist(L);int y;int x=1;L=(struct LNode*)malloc(sizeof(struct LNode)); if(!L){printf("\n 如没有申请到空间! ");return ;}L->next=NULL;r=L;fp=fopen("employee.txt","rb");while(!feof(fp)){p=(struct LNode*)malloc(sizeof(struct LNode)); if(!p){printf(" 如没有申请到空间!\n");exit(0);}if(fread(p,sizeof(struct LNode),1,fp)){p->next=NULL;r->next=p;r=p;count++;}}fclose(fp);//printf("\n=====>提示:导入%d条记录.\n",count); while(1){menu();printf("====>请选择:");scanf("%d",&y);if(y==7){if(saveflag==1){getchar();printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n");scanf("%c",&ch);if(ch=='y'||ch=='Y')Save(L);}printf("\n=====>提示:你已经退出系统,再见!\n");break;}switch(y){case 1:CreatList(L);do{printf("是否继续输入?(y/n)");getchar();scanf("%c",&m);if(m=='y'){CreatList(L);}}while(m!='n');break;case 2: printf("请输入查询方式(1按编号查询,2按姓名查找)");scanf("%d",&a);if(a==1){printf("请输入查询员工编号\n");scanf("%s",&id);SearchID(L,id);}if(a==2){printf("请输入查询员工姓名\n");scanf("%s",&name);SearchName(L,name);}break;case 3: printf("请选择排序条件:1.编号2.姓名3.年龄4.电话0.退出\n");scanf("%d",&a);if(a==1){printf("编号排序\n");SortID(L,id);}if(a==2){printf("姓名排序\n");SortName(L,name);}if(a==3){printf("年龄排序\n");SortAge(L,age); }if(a==4){printf("电话排序\n");SortPhone(L,phone);}break;case 4: printf("所有员工信息如下所示\n");Display(L);break;case 5: printf("请输入更改员工编号");getchar();scanf("%s",&id);Updata(L,id);break;case 6: printf("请输入删除员工编号");getchar();scanf("%s",&id);Delete(L,id);break;//case 7: x=0;//break;default:printf("请输入正确序号!\n");break;}}}。
数据结构课程设计代码

数据结构课程设计代码根据提供的输入输出需求,下面是一个示例的数据结构课程设计代码。
```pythonclass Node:def __init__(self, data):self.data = dataself.next = Noneclass LinkedList:def __init__(self):self.head = Nonedef add(self, data):new_node = Node(data)if self.head is None:self.head = new_nodeelse:current = self.headwhile current.next is not None:current = current.nextcurrent.next = new_nodedef remove(self, data):current = self.headprev = Nonewhile current is not None:if current.data == data:if prev is None:self.head = current.next else:prev.next = current.next returnprev = currentcurrent = current.nextdef display(self):current = self.headwhile current is not None:print(current.data, end=" ")current = current.nextprint()if __name__ == "__main__":linked_list = LinkedList()while True:print("1. Add element")print("2. Remove element")print("3. Display elements")print("4. Quit")choice = input("Enter your choice: ")if choice == "1":data = input("Enter element to add: ")linked_list.add(data)elif choice == "2":data = input("Enter element to remove: ")linked_list.remove(data)elif choice == "3":linked_list.display()elif choice == "4":breakelse:print("Invalid choice")```这个代码示例实现了一个简单的链表数据结构,在命令行中提供了添加元素、删除元素和显示元素的选项。
数据结构课程设计源代码(完整版)

算法与数据结构课程设计报告设计题目:专业班级学生学号指导教师2014年第1学期第一部分:需求分析1、系统名称:航空客运订票系统航空客运订票的业务活动包括:查询航线、客票预定和办理退票等。
要求在TC或VC环境下设计一个航空客运订票系统,以使上述业务可以借助计算机来完成。
2、要求:(1)每条航线所涉及的信息有:终点站名、航班号、飞机号、飞行日期(星期几)、乘员定额、余票量、已经订票的客户名单(包括姓名、订票量)以及等候替补的客户名单(包括姓名、所需票量)。
(2)作为模拟系统,全部数据可以只存放在内存中。
(3)通过此系统可以实现如下功能:①录入功能:可以录入航班情况②查询功能:根据客户提供的终点站名进行查询,可以输出以下信息:航班号、飞机号、星期几飞行和余票量等。
也可以根据航班号,查询飞机某个航线的情况。
③订票功能:根据客户提出的要求(姓名、终点站名、订票数量)查询该航班的余票量情况。
如尚有足够的余票,则为客户办理订票手续;若已满员或余票量少于订票数量,则需要重新询问客户要求,如需要,可登记排队候补。
④退票功能:根据客户提供的情况(姓名、日期、航班号),为客户办理退票手续,然后查询该航班是否有人排队候补,若有人排队,则为排在第一位的客户办理订票手续。
第二部分:系统设计图样一:设计说明1:添加航班:整个航班的信息保存在一个结构体flight中,采用结构体数组,每一个航班信息包含航班号、起飞时间、起飞城市、降落时间、降落城市、余票数量。
航班信息通过lulu()函数进行添加。
添加的信息保存在航班flight结构体数组中。
2:查询航班:查询板块分为两个部分,按姓名查找和按站名查找。
按姓名查找:通过所输入的姓名和已定客户的姓名相匹配,匹配成功则查找成功。
按站名查找:通过所输入的起始站名和终点站名进行匹配,匹配成功则查找成功。
3:订票功能:根据用户的姓名和航班号进行订票,如果所查找的航班号的余票满足用户需要的票数,则订票成功,该信息保存在Customer中,才用结构体数组,包含已定客户的姓名、客户ID、订的票数、起飞时间、起飞城市、降落时间、降落城市、航班号。
数据结构课程设计字典序(源代码)..

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<malloc.h>#define NULL 0#define ERROR -1#define stack_in_size 100#define stackincrement 10struct TreeNode /*树结点*/{char ch;int number; /*以该字符为结束的单词出现的个数*/struct TreeNode* pt[26]; /*指向后继的字母的26个指针*/};struct TreeNode *root;typedef struct TreeNode *Link_TreeNode;struct MAX_TEN /*存放出现频率最高的十个单词数据结构*/{char STRING[35];int count; /*字符串出现的次数*/int xiabao; /*字符数组位置的下标*/};struct MAX_TEN MAX[10];struct MAX_TEN MIN;struct DocumentNode /*文件结点*/{char ch; /*存放某个单词的一个字符*/int number; /*以该字符为结束的单词出现的个数*/ struct DocumentNode* pt[26]; /*指向后继的字母的26个指针*/struct Locationn *next; /*连接以该字符为结束的单词所在的位置*/ };typedef struct DocumentNode *Link_DocumentNode;Link_DocumentNode ROOT[301]; /*300个根节点指针,零号单元不用*/ struct Locationn /*单词在文件中的位置*/{int num;struct Locationn *next;};struct WORD /*单词链表结构*/{char strr[35];struct WORD *next;};typedef struct{char *base;char *top;int stacksize;}SQSTACK;SQSTACK S,T;SQSTACK Creat() /*创建空栈*/{SQSTACK s;s.base=(char*)malloc(stack_in_size*sizeof(char));s.top=s.base;s.stacksize=stack_in_size;return s;} /*全局变量栈*/char pop(SQSTACK &s) /*出栈*/{char e;if(s.top==s.base)return ERROR;e=*(--s.top);return e;}void push(SQSTACK &s,char e) /*入栈*/{if(s.top-s.base>=s.stacksize){ s.base=(char*)realloc(s.base,(s.stacksize+stackincrement )*sizeof(char));s.top=s.base+s.stacksize;s.stacksize+=stackincrement;}*s.top=e;s.top=s.top+1;}int isempty(SQSTACK s) /*判断栈是否为空*/{if(s.base==s.top)return 1;elsereturn 0;}Link_TreeNode creat() /*创建树结点,并返回指向该节点的指针*/ {int i;Link_TreeNode pt;pt=(Link_TreeNode)malloc(sizeof(TreeNode));pt->number=0;for(i=0;i<26;i++)pt->pt[i]=NULL;return pt;}void CREAT_DicTree() /*创建字典树*/{root=creat();Link_TreeNode q;FILE *fp;char *p;int ctmp;int jieshu;char str[35]; /*存放从文件中读入的单词*/ if((fp=fopen("vocabulary.txt","r"))==NULL)printf("cannot open vocabulary.txt\n");while(1){jieshu=fscanf(fp,"%s",str);/*从文件中读入字符串*/q=root;if(jieshu==-1)break;else{p=str;while(*p!='\0'){ctmp=*p-97;if(q->pt[ctmp]!=NULL)q=q->pt[ctmp];else{q->pt[ctmp]=creat();q=q->pt[ctmp];q->ch=*p;}p++;if(*p=='\0'){q->number++;break;}}}}}int Search(char str[],Link_TreeNode root) /*在字典树中搜索字符串str,并返回其出现的次数不存在时返回次数为0*/{int count,ctmp;char *p;p=str;Link_TreeNode q;q=root;while(*p!='\0'){ctmp=*p-97;if(q->pt[ctmp]==NULL){count=0; /*不存在时count置为0*/break;}else{q=q->pt[ctmp];p++;if(*p=='\0')count=q->number;}}return count;}Link_TreeNode Get_Last_Link(char str[]){int k;char *p;Link_TreeNode q=root;p=str;T.top=T.base;S=Creat();while(*p!='\0') /*前缀存入栈S中*/{push(S,*p);p++;}p=str;while(*p!='\0'){k=*p-97;if(q->pt[k]==NULL){q=q->pt[k];break;}else{q=q->pt[k]; /*指针q指向的结点中字符为当前*p的字符值*/p++;}}return q;}bool OutPrint(Link_TreeNode p,FILE *fp) /*递归将指针p所指的结点的指针数组所指向的所有单词写入文件中*/{int k;char temp;Link_TreeNode q;for(k=0;k<26;) /*扫描26个指针*/{if(p->pt[k]==NULL)k++;else{q=p->pt[k];push(S,q->ch);if(q->number>0) /*输出该单词*/{while(!isempty(S)){temp=pop(S);push(T,temp); /*将栈S中的元素全部弹入T栈中*/}char shuzu[35];char tempp[2];shuzu[0]='\0';while(!isempty(T)) /*逐个将T栈中元素弹入S栈中*/{tempp[0]=pop(T);tempp[1]='\0';strcat(shuzu,tempp);push(S,tempp[0]);}fprintf(fp,"%s\n",shuzu);/*将出现的该单词写入文件中*/}OutPrint(q,fp); /*递归调用*/pop(S);k++;}}if(k==26)return true; /*没有后继指针*/}void RECHANGE_MIN(char tepp[],int cunt) /*数组中保存的十个最大的单词*/{strcpy(MAX[MIN.xiabao].STRING,tepp);MAX[MIN.xiabao].count=cunt;int k;MIN=MAX[0];for(k=1;k<10;k++){if(MIN.count>MAX[k].count)MIN=MAX[k];}}bool GOT_MAX_TEN(Link_TreeNode p)/*递归得到指针p所指的结点的指针数组所指向的所有单词中出现次数最高的十个单词*/{int k;char temp;Link_TreeNode q;for(k=0;k<26;) /*扫描26个指针*/{if(p->pt[k]==NULL)k++;else{q=p->pt[k];push(S,q->ch);if(q->number>0){if(q->number>MIN.count){while(!isempty(S)){temp=pop(S);push(T,temp);}char shuzu[35];char tempp[2];shuzu[0]='\0';while(!isempty(T)){tempp[0]=pop(T);tempp[1]='\0';strcat(shuzu,tempp);push(S,tempp[0]);}RECHANGE_MIN(shuzu,q->number);}}GOT_MAX_TEN(q);pop(S);k++;}}if(k==26)return true;}Link_DocumentNode CREAT()/*创建一个文件型的数据结构结点,并返回指向该节点的指针*/{int i;Link_DocumentNode p;p=(Link_DocumentNode)malloc(sizeof(struct DocumentNode));p->number=0;for(i=0;i<26;i++){p->pt[i]=NULL;}p->next=NULL; /*文件初始化*/return p;}void CREAT_DocumentTree() /*读入文件,创建文件树*/{Link_DocumentNode q;struct Locationn *LL;FILE *fp;char *p;int ctmp;int jieshu;int Location; /*定位单词在文章中的位置*/int k;char str[35]; /*存放从文件中读入的单词*/if((fp=fopen("Document.txt","r"))==NULL)printf("cannot open Document.txt\n");while(1){jieshu=fscanf(fp,"%s",str);if(jieshu==-1)break; /*文件中单词已读完*/if(!strcmp(str,"Document")){fscanf(fp,"%d",&k);ROOT[k]=CREAT();Location=1;fscanf(fp,"%s",str);}q=ROOT[k];p=str;while(*p!='\0') /*处理每个单词*/{ctmp=*p-97;if(q->pt[ctmp]!=NULL)q=q->pt[ctmp];else{q->pt[ctmp]=CREAT();q=q->pt[ctmp];q->ch=*p;}p++;if(*p=='\0'){q->number++;if(q->next==NULL){LL=(struct Locationn *)malloc(sizeof(struct Locationn));LL->num=Location;q->next=LL;LL->next=NULL;Location++;break;}else{LL=q->next;while(LL->next!=NULL)LL=LL->next;LL->next=(struct Locationn *)malloc(sizeof(struct Locationn));LL=LL->next;LL->next=NULL;LL->num=Location;Location++;break;}}}}}int Search_Doc(char str[],Link_DocumentNode root)/*在文件树中搜索字符串str,不存在时返回次数为0,存在返回其出现的次数*/{int count,ctmp;char *p;p=str;Link_DocumentNode q;q=root;while(*p!='\0') /*逐个扫描该字符串中的每个字符*/{ctmp=*p-97;if(q->pt[ctmp]==NULL){count=0;break;}else{q=q->pt[ctmp];p++;if(*p=='\0')count=q->number;}}return count;}void SORT_MAX_Ten() /*对出现频率最高的十个单词从大到小排序*/ {int i,j,temp;struct MAX_TEN ctmp;for(i=0;i<9;i++) /*选择排序*/{temp=i;for(j=i+1;j<10;j++)if(MAX[temp].count<MAX[j].count)temp=j;if(temp!=i){ctmp=MAX[temp];MAX[temp]=MAX[i];MAX[i]=ctmp;}}}struct WORD *Creat_two_word_link(char str1[],char str2[]){struct WORD *head,*tempary,*pt;tempary=head=NULL;char ttmp[35];char *p,*q;int count;for(count=1;count<=2;count++){ /*扫描两个单词*/if(count==1)p=str1;else{p=str2;}q=ttmp;while(*p!='\0'){*q=*p;p++;q++;}*q='\0';pt=(struct WORD *)malloc(sizeof(struct WORD));strcpy(pt->strr,ttmp);if(head==NULL) /*扫描第一个单词的情况*/{tempary=head;}else /*扫描第二个单词的情况*/{tempary->next=pt;tempary=pt;}}tempary->next=NULL;return head;}struct WORD *Creat_multi_word_link(int length,FILE *fp){char ttmp[35];char string[35]; /*存放读入是的字符串*/int count;char *p;char *q;struct WORD *head,*pt,*tempary;tempary=head=NULL; /*对指针进行初始化*/ for(count=1;count<=length;count++){fscanf(fp,"%s",string);p=string;q=ttmp;while(*p!='\0'){*q=*p;p++;q++;}*q='\0';pt=(struct WORD *)malloc(sizeof(struct WORD));strcpy(pt->strr,ttmp);if(head==NULL){head=pt;tempary=head;}else{tempary->next=pt;}}tempary->next=NULL;return head;}void Search_Match_Word(struct WORD *head,int length,FILE *fp){Link_DocumentNode q;int circle;int ctmp;struct WORD *point;struct Locationn *list1;struct Locationn *list2;list1=(struct Locationn*)malloc(sizeof(struct Locationn));list2=(struct Locationn*)malloc(sizeof(struct Locationn));list2->next=NULL;struct Locationn *pt1;struct Locationn *pt2;struct Locationn *pt3;int i;char *p;for(circle=0;circle<=300;){nextcircle:circle++;if(circle>300)break; /*文件树扫描结束*/ for (i=1,point=head->next;i<=length;i++){ /*逐个扫描从文件中读入的n个字符串*/p=point->strr; /*指向当前扫描的该字符串的首地址*/q=ROOT[circle]; /*q指向第circle个文件数*/while (*p!='\0'){ctmp=*p-97;if(q->pt[ctmp]==NULL)goto nextcircle;else{ /*存在时继续在文件树中扫描直到该单词的结尾*/q=q->pt[ctmp];}p++;if(*p=='\0'){if(i==1)list1->next=q->next;else{pt1=list1->next;while (pt1!=NULL){pt2=q->next;while (pt2!=NULL){if(pt1->num+1!=pt2->num)pt2=pt2->next;else{pt3=list2;while (pt3->next!=NULL)pt3=pt3->next;pt3->next=(struct Locationn *)malloc(sizeof(struct Locationn));pt3=pt3->next;pt3->num=pt2->num;pt3->next=NULL;pt2=pt2->next;}}pt1=pt1->next;}//whilelist1->next=list2->next;if(list1->next==NULL)goto nextcircle;list2->next=NULL;}//else}}point=point->next; /*扫描该字符串的下一个单词*/}if(list1->next!=NULL){fprintf(fp,"%d ",circle);}list2->next=NULL;}//circle}void OPEN_SearchWordInV ocabulary() /*生成SearchWordInV ocabulary_Result.txt*/ {FILE *fp1;FILE *fp2;char str[35];int count; /*存放查找该单词时出现的次数*/int k=1;int jieshu; /*结束判断的标志*/if((fp1=fopen("SearchWordInV ocabulary.txt","r"))==NULL)printf("cannot open SearchWordInV ocabulary.txt\n");if((fp2=fopen("SearchWordInVocabulary_Result.txt","w"))==NULL)printf("cannot write SearchWordInV ocabulary_Result.txt\n");jieshu=fscanf(fp1,"%s",str); /*文件读取结束的标志*/while(jieshu!=-1){fprintf(fp2,"%s %d:\n","CASE",k);k++;count=Search(str,root);if(count==0)fprintf(fp2,"%s\n","NO");elsefprintf(fp2,"%d\n",count);jieshu=fscanf(fp1,"%s",str);}fclose(fp1);fclose(fp2);}void OPEN_TotPrefixWord() /*生成TotPrefixWord_Result.txt*/{FILE *fp1;FILE *fp2;char str[35];int count;int k=1;int jieshu;Link_TreeNode p_link;if((fp1=fopen("TotPrefixWord.txt","r"))==NULL)printf("cannot open SearchWordInV ocabulary.txt\n");if((fp2=fopen("TotPrefixWord_Result.txt","w"))==NULL)printf("cannot write SearchWordInV ocabulary_Result.txt\n");jieshu=fscanf(fp1,"%s",str); /*读入一个单词*/while(jieshu!=-1){fprintf(fp2,"%s %d:\n","CASE",k);k++;p_link=Get_Last_Link(str); /*找到在单词树中指向该单词最后一个字符的指针*/if(p_link!=NULL){fprintf(fp2,"%s\n",str);OutPrint(p_link,fp2);}jieshu=fscanf(fp1,"%s",str); /*从文件中读入下一个单词*/ }fclose(fp1);fclose(fp2);}void OPEN_PrefixFrequence() /*生成PrefixFrequence_Result.txt*/{FILE *fp1;FILE *fp2;char str[35];int count;int k=1;int i;int jieshu;Link_TreeNode p_link;if((fp1=fopen("PrefixFrequence.txt","r"))==NULL)printf("cannot open SearchWordInVocabulary.txt\n");if((fp2=fopen("PrefixFrequence_Result.txt","w"))==NULL)printf("cannot write SearchWordInV ocabulary_Result.txt\n");jieshu=fscanf(fp1,"%s",str); /*从文件中读入一个该单词*/ while(jieshu!=-1){fprintf(fp2,"%s %d:\n","CASE",k);k++;p_link=Get_Last_Link(str);if(p_link!=NULL){for(i=0;i<10;i++){MAX[i].xiabao=i;MAX[i].count=0;}MIN=MAX[0];GOT_MAX_TEN(p_link);SORT_MAX_Ten();if(p_link->number>0){for(i=0;i<10;i++){if(MAX[i].count==0){strcpy(MAX[i].STRING,str);MAX[i].count=p_link->number;break;}}}SORT_MAX_Ten();for(i=0;i<10;i++){if(MAX[i].count>0){fprintf(fp2,"%s %d\n",MAX[i].STRING,MAX[i].count);}}}jieshu=fscanf(fp1,"%s",str);}fclose(fp1);fclose(fp2);}void OPEN_MostFrequenceWord() /*生成MostFrequenceWord.txt*/ {FILE *fp;int k;for(k=0;k<10;k++){MAX[k].xiabao=k;MAX[k].count=0;}MIN=MAX[0];if((fp=fopen("MostFrequenceWord.txt","w"))==NULL)printf("cannot write MostFrequenceWord.txt\n");S=Creat();GOT_MAX_TEN(root);SORT_MAX_Ten();for(k=0;k<10;k++)if(MAX[k].count>0)fprintf(fp,"%s %d\n",MAX[k].STRING,MAX[k].count);fclose(fp);}void main(){printf("*****************基本型问题************************\n");CREAT_DicTree();/*第一题,读入vocabulary文件,建立存放单词的字典树*/printf("The First problem has been solved,a dictionary tree has been buildt\n");OPEN_SearchWordInVocabulary();/*第二题,生成SearchWordInV ocabulary_Result.txt*/ printf("The Second problem has been solved,SearchWordInVocabulary_Result.txt formed \n"); printf("*****************扩展型问题************************\n");OPEN_TotPrefixWord();/*第三题,生成TotPrefixWord_Result.txt*/printf("The Third problem has been solved,TotPrefixWord_Result.txt formed \n");OPEN_PrefixFrequence();/*第四题,生成PrefixFrequence_Result.txt*/printf("The Forth problem has been solved,PrefixFrequence_Result.txt formed \n");OPEN_MostFrequenceWord();/*第五题,生成MostFrequenceWord.txt*/printf("The Fifth problem has been solved,MostFrequenceWord.txt formde\n");printf("*****************高级型问题************************\n");CREAT_DocumentTree();/*第六题,读入Document文件,建立存放文件的树*/printf("The Sixth problem has been solved,WordInDocument_Result.txt formed\n");}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include <stdio.h>#include<stdlib.h>#include <string.h>#include<malloc.h>#define MAXSIZE 1000typedef char DataType;typedef struct node{DataType ch[MAXSIZE];struct node *next;}Lstring;/*****输入文章*****/Lstring *input(){Lstring *p,*head;int i=0;printf ("请输入一页文章,若要换行,请直接敲回车键,若想结束请按@:\n");p=(Lstring *)malloc(sizeof(Lstring));head=p;p->ch[i]=NULL;p->next=NULL;char str[200];while(1){gets(str);if(strlen(str)>100){printf("每行最多输入100字符");break;}if(str[0]==64){str[0]='\0';p->ch[0]=str[0];break;}p->next=(Lstring *)malloc(sizeof(Lstring));strcpy(p->ch,str);if(str[strlen(str)-1]==64){p->ch[strlen(str)-1]='\0';break;}p=p->next;}p->next=NULL;return head;}/****输出文章*****/Lstring *OutPut(Lstring *head){Lstring *p=head;do{printf("%s\n",p->ch);}while((p=p->next)!=NULL);return head;}/****统计字母的个数*****/int Alphabet(Lstring *head){Lstring *p=head;int count=0;do{int Len;Len=strlen(p->ch);for(int i=0;i<Len;i++)if((p->ch[i]>='a'&&p->ch[i]<='z')||(p->ch[i]>='A'&&p->ch[i]<='Z')) count++;}while((p=p->next)!=NULL);return count;}/****统计数字的字数*****/int Num(Lstring *head){Lstring *p=head;int count=0;do{int Len;Len=strlen(p->ch);for(int i=0;i<Len;i++)if(p->ch[i]>='0' && p->ch[i]<='9')count++;}while((p=p->next)!=NULL);return count;}/****统计空格的字数*****/int Space(Lstring *head){Lstring *p=head;int count=0;do{int Len;Len=strlen(p->ch);for(int i=0;i<Len;i++)if(p->ch[i]==32)count++;}while((p=p->next)!=NULL);return count;}/*统计文章的总字数*/int All(Lstring *head){Lstring *p=head;int count=0;do{count+=strlen(p->ch);}while((p=p->next)!=NULL);return count;}/****串的简单模式匹配*****/int FindString(Lstring *head,char *str){Lstring *p=head;int count=0;int h=0;int len1=0;int len2=strlen(str);int i,j,k;do{len1=strlen(p->ch);for(i=0;i<len1;i++){if(p->ch[i]==str[0]){k=0;for(j=0;j<len2;j++)if(p->ch[i+j]==str[j]) k++;if(k==len2){count++;i=i+k-1;}}}}while((p=p->next)!=NULL);return count;}void delstringword(char *s,char *str){char *p;int count,len,i,j;char s1[80];p=strstr(s,str);len=strlen(s);i=len-strlen(p);j=i+strlen(str);count=0;for(int m=0;m<i;m++)s1[count++]=s[m];for(int n=j;n<len;n++)s1[count++]=s[n];s1[count]='\0';strcpy(s,s1);}Lstring *DelString(Lstring *head,char *str){Lstring *p=head;do{while(strstr(p->ch,str)!=NULL)delstringword(p->ch,str);}while((p=p->next)!=NULL);return head;}void main(){int i=0;int m;Lstring *head;char s1[20],s2[20];head=input();printf("输入的文章为:\n");head=OutPut(head);printf("\n");printf("全部字母数:%d \n",Alphabet(head));printf("数字个数:%d \n",Num(head));printf("空格个数: %d \n",Space(head));printf("文章总字数: %d \n",All(head));printf("\n");printf("**********************\n");printf("* 菜单 *\n");printf("**********************\n");printf("* 1---统计字符串 *\n");printf("* 2---删除字符串 *\n");printf("* 0---退出 *\n");printf("**********************\n");do{printf("请输入你要选择的操作(0~2):");scanf("%d",&m);switch(m){case 0:exit(0);break;case 1:printf("请输入要统计的字符串:");scanf("%s",&s1);printf("%s在文章中出现的次数为:%d \n",s1,FindString(head,s1));printf("\n");break;case 2:printf("请输入要删除的某一字符串:");scanf("%s",&s2);head=DelString(head,s2);printf("删除%s后的文章为:\n",s2);OutPut(head);break;}}while(m!=0);}。