数据结构实习报告12345 联系客服

发布时间 : 星期六 文章数据结构实习报告12345更新完毕开始阅读1f4d4353a300a6c30c229f71

printf(\请输入表达式,如:45+36#,必须以#号结尾!\\n\ A[i]=getchar(); while(A[i++]!='#') { A[i]=getchar(); } A[i]='\\0'; infix_exp_value(A,B); printf(\ printf(\ printf(\上式的结果为: \ printf(\ return 0; getch(); }

2.4 测试结果:

1)输入11+(9-3)*(8/2)#

2)输入3+(1/8)*(16-7)#

3 学生成绩查询系统

按学号排序后对学号进行折半查找。 随机输入以学号为关键字的学生信息并构建二叉排序树,对学号进行二叉排序树查找。

3.1设计思路

这个程序主要是实现按学号对8名学生的信息进行查找,其中查找方式分为三种:顺序查找、折半查找、二叉排序树查找。由于顺序查找、折半查找很容易实现,而二叉排序树查找需要构建二叉排序树,再进行二叉排序树查找,所以在这一步骤上有点难度。

16

学生信息包括序号、姓名、成绩,其中学号和姓名都是由字符实现,成绩由整形实现。在输入学生信息时直接按学号顺序输入,这样便省去了在程序中对学生的学号从新进行排序,在二叉排序树的查找过程中,只能查找那些参与构建二叉排序树的学号,二叉排序树是以第一个输入的学生学号为根结点构造二叉排序树的。

3.2系统流程图:

3.3 程序:

#include \#include #include #include typedef struct { char sno[11]; //学号 char name[16]; //姓名 int score; //成绩 }student;

typedef struct BinSTreeNode { char hao[11]; char ming[16]; int fen; struct BinSTreeNode *lchild; struct BinSTreeNode *rchild; }*BTree;

int shun_search(student stu[],int n,char x[]) { int i,j;

17

for(i=0;i

int zhe_search(student stu[],int n,char x[]) { int low,mid,high; low=0;high=n-1; while(low<=high) { mid=(low+high)/2; if(strcmp(stu[mid].sno,x)==0) { printf(\所查找的学生信息如下:\\n 学号\\t 姓名\\t成绩\\n\ printf(\ return 0; } else if(strcmp(stu[mid].sno,x)>0) high=mid-1; else low=mid+1; } return 0; }

void BSTree(BTree *t,student k) { BTree r; if(*t==NULL) { r=(BTree)malloc(sizeof(struct BinSTreeNode)); strcpy(r->hao,k.sno); strcpy(r->ming,k.name); r->fen=k.score; r->lchild=r->rchild=NULL; *t=r; return; } else if(strcmp(k.sno,((*t)->ming))<=0) BSTree(&((*t)->lchild),k); else BSTree(&((*t)->rchild),k); }

18

BTree BSTreeSearch(BTree t,char x[]) { if(t==NULL) return NULL; if(strcmp(t->hao,x)==0) return t; if(strcmp(t->hao,x)>=0) return BSTreeSearch(t->lchild,x); else return BSTreeSearch(t->rchild,x); }

main() { student stu[40]; int i,j,k,n,b; char x[12]; printf(\学生成绩查询系统\\n\\n\ printf(\请输入本次统计的学生数:\ scanf(\ printf(\请输入这些学生的信息:\\n\ printf(\学号\\t姓名 成绩\\n\ for(i=0;i

19