这几天终于开始做项目了,原本轻松的日子终于有了些紧迫感,这篇总结就来介绍一下我的项目和做项目的思路。
我选择的是成绩管理系统,我有现成的五子棋,但是那个做的太拉了也没有用到多少数据结构的相关知识,所以在听到二叉搜索树这个数据结构后我就想好了要做什么那就是成绩管理系统。
为了这次的项目,我学习了easyx来做图形页面(虽然做的很拉(悲)),还学习并实现了二叉搜索树,这里说一下我对二叉搜索树的理解,我对它的印象就三个字:真的快!,建树后的查找,每一次都相当与一次二分查找,这可比普通找快多了,还有一个让我惊讶的点就是按照中序输出的二叉搜索树可以直接将数据排列好(神奇),建立,查找,插入都很简单,但世界上没有十全十美的东西,二叉搜索树的删除可要下点功夫,附上我手敲的二叉搜索树实现代码(删除还在开发中):
#include<stdio.h>
#include<malloc.h>
struct tree{
int data;
struct tree *lc,*rc;
};
struct tree *head=NULL,*p,*t,*q;
int n;
void creatandadd(int x);
void dfs(struct tree *t);
int find(int x);
void Delete(int x);
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
creatandadd(x);
}
dfs(head);
printf("\n");
int x;
scanf("%d",&x);
printf("%d\n",find(x));
scanf("%d",&x);
Delete(x);
dfs(head);
return 0;
}
void creatandadd(int x){
if(head==NULL){
head=(struct tree*)malloc(sizeof(struct tree));
head->data=x;
head->lc=NULL;
head->rc=NULL;
return ;
}else{
struct tree *q;
p=head;
while(p!=NULL){
q=p;
if(x>p->data){
p=p->rc;
}else{
p=p->lc;
}
}
if(q->data>x){
t=(struct tree*)malloc(sizeof(struct tree));
t->data=x;
t->lc=NULL;
t->rc=NULL;
q->lc=t;
}else{
t=(struct tree*)malloc(sizeof(struct tree));
t->data=x;
t->lc=NULL;
t->rc=NULL;
q->rc=t;
}
}
}
void dfs(struct tree *t){
printf("%d ",t->data);
if(t->lc==NULL&&t->rc==NULL){
return ;
}
if(t->lc!=NULL) dfs(t->lc);
if(t->rc!=NULL) dfs(t->rc);
}
int find(int x){
p=head;
int step=1;
while(p!=NULL){
if(p->data>x){
p=p->lc;
step=2*step;
continue;
}
if(p->data<x){
p=p->rc;
step=2*step+1;
continue;
}
if(p->data==x){
return step;
}
}
return -1;
}
void Delete(int x){
p=head;
while(p->data!=x){
if(p->data>x){
p=p->lc;
}else{
p=p->rc;
}
}
if(p->lc==NULL&&p->rc==NULL){
free(p);
}else if(p->lc==NULL){
q=p;
p=p->rc;
free(q);
}else if(p->rc==NULL){
q=p;
p=p->lc;
free(q);
}
}
最后说一下我的项目思路,先利用easyx做出主页面再结合文件操作和二叉搜索树去实现比较高效的查找与更改,最后带上我现在的项目进程:
这简单低奢(垃圾)的主页面,
目前已完成成绩的录入与修改。