这里是2020/12/7就开始的致命课程设计QAQ
//东拼西凑最终归档

(一)链表

  • 报数问题(单向循环链表)
#include<bits/stdc++.h>using namespace std;/************约瑟夫问题****************/typedef struct node
{int data;struct node *next;
}LNode,*LinkList;void creatLink(LinkList &L,int num){LinkList s,r;int i;r=L;for(i=1;i<=num;i++){s=new LNode;s->data=i;r->next=s;r=s;}r->next=L->next;}
LinkList YSF(LinkList L,int k)
{LinkList p;int i;p=L->next;while(p->next!=p){for(i=1;i<k-1;i++){p=p->next;}p->next=p->next->next;p=p->next;}return p;
}
int main()
{LinkList L,s;int n,k;L=new LNode;cin>>n>>k;creatLink(L,n);s=YSF(L,k);cout<s->data<<endl;return 0;
}

(二)栈与队列

  • 停车场问题

这里有bug:简单讲就是非顺序出车会出错

#include<bits/stdc++.h>
using namespace std;#define  stacksize  10typedef  struct  sqstack{int  data[stacksize];int  top;} SqStackTp;void INITstack(SqStackTp &s)//初始化栈
{s.top=-1;memset(s.data,0,sizeof(s.data));
}
void InStack(SqStackTp &s,int num)//入栈
{if(s.top!=stacksize-1)//栈未满{s.top++;s.data[s.top]=num;}
}
int OutStack(SqStackTp &s)//出栈
{int x;if(s.top!=-1){x=s.data[s.top];s.top--;}return x;
}typedef struct  linked_queue
{int  data;struct  linked_queue  * next;
}LqueueTp;
typedef  struct
{LqueueTp  *front ,  *rear ;
} QueptrTp;void INITQueue(QueptrTp &Q)//初始化队列
{Q.front=Q.rear=new LqueueTp;Q.front->next=NULL;
}
void InQueue(QueptrTp &Q,int x)//入队
{LqueueTp *p1;p1=new LqueueTp;//指针节点p1->data=x;p1->next=NULL;//尾插Q.rear->next=p1;Q.rear=p1;
}
int OutQueue(QueptrTp &Q)//出队
{int x;LqueueTp *p;if(Q.front!=Q.rear){p=Q.front->next;x=p->data;Q.front->next=p->next;if(p==Q.rear){Q.rear=Q.front;}delete(p);}return x;
}
//全局变量等候便道队列//QueptrTp Q;//全局变量临时栈//SqStackTp tmpstack;//SqStackTp parkstack;//指令1--进入停车场
void INparking(SqStackTp &parkstack,int num,QueptrTp &Q)
{if(parkstack.top==stacksize-1)//栈满{cout<<"停车位已满,正在进入等候区"<<endl;InQueue(Q,num);//等候入队列}else//入栈{InStack(parkstack,num);cout<<"停车成功"<<endl;}}
void returnstack(SqStackTp &tmpstack,SqStackTp &parkstack)//非目标车从临时栈回车库
{int x;while(tmpstack.top!=-1)//仍未清空{x=OutStack(tmpstack);InStack(parkstack,x);}
}
//指令2--离开停车场
void OUTparking(SqStackTp &parkstack,int num,SqStackTp &tmpstack,QueptrTp &Q)
{int i,x,y;for(i=1;i<=10;i++){x=OutStack(parkstack);//出栈if(x==num){//是目标车位returnstack(tmpstack,parkstack);//非目标车回车库cout<<"出车成功!"<<endl;if(Q.front!=Q.rear)//有车等待{y=OutQueue(Q);//出队列cout<<y<<"号等待位进入车库"<<endl;INparking(parkstack,y,Q);//指令1}break;}else if(parkstack.top!=-1){//不是目标车且栈不为空InStack(tmpstack,x);  //进入临时栈}else{cout<<"未找到该车!!!请重新确认车号"<<endl;returnstack(tmpstack,parkstack);//非目标车回车库break;}}}
void UI1()
{cout<<"--------------"<<endl;cout<<"请选择操作:1停车  2出车 0退出系统"<<endl;
}
void UI2()
{cout<<"请输入车号:"<<endl;cout<<"--------------"<<endl;
}
int main()
{QueptrTp Q;SqStackTp tmpstack;SqStackTp parkstack;INITQueue(Q);//初始化 等候队列INITstack(tmpstack);//初始化 临时栈INITstack(parkstack);//初始化 停车栈int opration=-1,num,x;while(opration!=0){UI1();cin>>opration;if(opration==1)//进车{UI2();cin>>num;INparking(parkstack,num,Q);// x=OutStack(parkstack);//cout<<x<<"测试"<<endl;}if(opration==2){UI2();cin>>num;OUTparking(parkstack,num,tmpstack,Q);}if(opration==0)break;}return 0;
}

(三)树型结构题目

  • 树转换成二叉树(以及树的遍历)

这里是星星的code~//拿来学习

#include <iostream>
#include <bits/stdc++.h>
using namespace std;//树的定义
typedef struct CSNode
{char data;struct CSNode *firstchild,*nextsibling;
}CSNode,*CSTree;//二叉树的定义
typedef struct BTNode
{char data;struct BTNode *lchild;struct BTNode *rchild;
}BTNode;//栈的定义
typedef struct Stack
{CSTree data;struct Stack *next;
}Sqstack,*LinkStack;//队列的定义
typedef struct Sqnode
{CSTree data;struct Sqnode *next;
}SqNode,*LinkQueue;
typedef struct
{LinkQueue front,rear;
}QueueTr;//先序输入创建一棵树
CSTree CreateCSTree()
{char ch;CSTree CTp=NULL;scanf("%c",&ch);if(ch!='0'){CTp=new CSNode;CTp->data=ch;CTp->firstchild=CreateCSTree();CTp->nextsibling=CreateCSTree();}return CTp;
}//树转换成二叉树
BTNode *ExchangeToBTree(CSTree ct)
{if(ct==NULL)return NULL;else{BTNode *bt=new BTNode;bt->data=ct->data;bt->lchild=ExchangeToBTree(ct->firstchild);bt->rchild=ExchangeToBTree(ct->nextsibling);return bt;}
}//二叉树转换成树
CSTree ExchangeToCSTree(BTNode *bt)
{if(bt==NULL)return NULL;else{CSTree ct=new CSNode;ct->data=bt->data;ct->firstchild=ExchangeToCSTree(bt->lchild);ct->nextsibling=ExchangeToCSTree(bt->rchild);return ct;}
}//树的先根递归遍历
void preorder_cstree(CSTree ct)
{if(ct!=NULL){printf("%c",ct->data);preorder_cstree(ct->firstchild);preorder_cstree(ct->nextsibling);}
}
//树的后根递归遍历
void rearorder_cstree(CSTree ct)
{if(ct!=NULL){rearorder_cstree(ct->firstchild);printf("%c",ct->data);rearorder_cstree(ct->nextsibling);}
}int StackEmpty(LinkStack s)
{if(s==NULL)return 1;return 0;
}
void PushStack(LinkStack &s,CSTree p)
{LinkStack sq;sq=new Sqstack;sq->data=p;sq->next=s;s=sq;
}
void PopStack(LinkStack &s,CSTree &q)
{q=s->data;s=s->next;
}
//树的先根非递归遍历
void preput_cstree(CSTree ct)
{LinkStack S;S=NULL;CSTree root;root=ct;while(root!=NULL||!StackEmpty(S)){if(root!=NULL){cout<<root->data;PushStack(S,root);root=root->firstchild;}else{CSTree q;PopStack(S,q);root=q->nextsibling;}}
}
//树的后根非递归遍历
void rearput_cstree(CSTree ct)
{LinkStack S;S=NULL;CSTree root;root=ct;while(root!=NULL||!StackEmpty(S)){if(root!=NULL){PushStack(S,root);root=root->firstchild;}else{CSTree q;PopStack(S,q);cout<<q->data;root=q->nextsibling;}}
}void PushQueue(QueueTr &Q,CSTree ct)
{if(ct==NULL)return;LinkQueue p;p=new SqNode;p->data=ct;p->next=NULL;Q.rear->next=p;Q.rear=p;
}
void PopQueue(QueueTr &Q)
{if(Q.front->next==Q.rear)Q.rear=Q.front;Q.front->next=Q.front->next->next;
}
//树的层次序非递归遍历
void cengciput_cstree(CSTree ct)
{QueueTr Q;Q.front=Q.rear=new SqNode;Q.front->next=NULL;if(ct==NULL)return;PushQueue(Q,ct);while(Q.front!=Q.rear){LinkQueue p;p=Q.front->next;cout<<p->data->data;PushQueue(Q,p->data->firstchild);PushQueue(Q,p->data->nextsibling);PopQueue(Q);}
}
int main()
{CSTree TREE,CT;BTNode *BT;TREE=CreateCSTree();BT=ExchangeToBTree(TREE);CT=ExchangeToCSTree(BT);cout<<"先根递归遍历树:";preorder_cstree(CT);cout<<endl;cout<<"后根递归遍历树:";rearorder_cstree(CT);cout<<endl;cout<<"先根非递归遍历树:";preput_cstree(CT);cout<<endl;cout<<"后根非递归遍历树:";rearput_cstree(CT);cout<<endl;cout<<"层次非递归遍历树:";cengciput_cstree(CT);cout<<endl;return 0;
}/*ab  c  d
e f
*//*
#define MAXSIZE 255
static int id=0;
typedef struct //数据的结构体
{int id;char name[MAXSIZE];
}ElementType;
typedef struct cbtree
{ElementType data;struct cbtree *firstchilld;//长子节点struct cbtree *nextsibling;//兄弟节点
}CbTree;//树节点结构体
int  createcbtree(CbTree*node);//创建树(孩子兄弟法)
void initcbtree(CbTree*tree);//初始化树
void testcbtree();//测试函数
void preordercbtree(CbTree*node);//前序遍历
int main()
{testcbtree();//测试函数return 0;
}
void initcbtree(CbTree*tree)//初始化树
{tree->firstchilld=NULL;//初始化空树的长子节点 为创建孩子节点空间 做前提tree->nextsibling=NULL;}
void testcbtree()//测试函数
{CbTree*tree;tree=(CbTree*)malloc(sizeof(CbTree));if(tree!=NULL){initcbtree(tree);printf("请输入根节点的数据:\n");createcbtree(tree);printf("前序遍历的结果为;\n");preordercbtree(tree);//遍历树}
}
int createcbtree(CbTree*node)//创建树(孩子兄弟法)
{char inputname  [MAXSIZE];gets(inputname);if(strcmp(inputname,"#")==0){return 0;}node->data.id=++id;strcpy(node->data.name,inputname);node->firstchilld=(CbTree*)malloc(sizeof(CbTree));node->nextsibling=(CbTree*)malloc(sizeof(CbTree));printf("请输入长子节点");if(createcbtree(node->firstchilld)==0){free(node->firstchilld);node->firstchilld=NULL;}printf("请输入兄弟节点");if(createcbtree(node->nextsibling)==0){free(node->nextsibling);node->nextsibling=NULL;}return 1;}
void preordercbtree(CbTree*node)//前序遍历(孩子兄弟法)
{if(node!=NULL){printf("[%d,%s]-",node->data.id,node->data.name);CbTree*p=node->firstchilld;preordercbtree(p);//if的判断用在判断长子节点的结束 便于接下来的兄弟节点的遍历//一直遍历长子节点 之后再遍历兄弟节点  长子节点为空 结束长子节点的遍历while(p)//长子节点结束 一直遍历兄弟节点  兄弟节点结束再遍历长子节点{p=p->nextsibling;preordercbtree(p);}}}
/*if(node==NULL)//采用层次规则创建{node=(CbTree*)malloc(sizeof(CbTree));node->firstchilld=NULL;node->nextsibling=NULL;}
*/

这里是我未完全实现的…ORZ

#include <bits/stdc++.h>
using namespace std;#define MAX_TREE_SIZE 100
typedef struct
{int data;int parent; //双亲位置域
}PTNode;
//双亲表示法树结构
typedef struct
{PTNode node[MAX_TREE_SIZE];int count;//根的位置和节点个数
}PTree;void init_ptree(PTree *tree)//初始化树结点
{tree->count=-1;
}
typedef struct node
{int  data;struct node *firstchild,*rightsib;//孩子兄弟
}BTNode,*BTree;BTNode GetTreeNode(int x)
{BTNode t;t.data=x;t.firstchild=t.rightsib=NULL;return t;
}void print_ptree(PTree T)//输出树
{int i;cout<<"  序号   节点   双亲 "<<endl;for(i=0;i<=T.count;i++)//没到根位置i++{cout<<"    "<<i<<"      "<<T.node[i].data<<"     "<<T.node[i].parent<<endl;}
}PTree CreateTree(PTree T)
{int i=1;int fa,ch;PTNode p;for(i=1;ch!=-1;i++){cout<<"输入第"<<i<<"结点"<<endl;cin>>fa>>ch;cout<<endl;p.data=ch;p.parent=fa;T.count++;//根节点的位置T.node[T.count].data=p.data;T.node[T.count].parent=p.parent;}cout<<endl;cout<<"创建树的具体情况如下:"<<endl;print_ptree(T);return T;
}
//转换成二叉树
BTNode *chang(PTree T)
{int i,j=0;BTNode p[MAX_TREE_SIZE];BTNode *ip,*ir,*is,*Tree;//is目标根,ip目标节点,ir连接右兄弟ip=new BTNode;ir=new BTNode;is=new BTNode;Tree=new BTNode;for(i=0;i<T.count;i++)//得到结点同时初始化first=right=NULL{p[i]=GetTreeNode(T.node[i].data);}for(i=1;i<T.count;i++){ip=&p[i];//第二个is=&p[j];//根while(T.node[i].parent!=is->data)//控制同一个父亲,否则跳下一层{j++;is=&p[j];}if(!(is->firstchild))//长子为空{is->firstchild=ip;//录入长子ir=ip;}else//次子连接{ir->rightsib=ip;ir=ip;}}Tree=&p[0];//二叉树return Tree;
}
//先序输出二叉树
void PrintBTree(BTNode *root)
{int i;if(root){cout<<"---"<<root->data;PrintBTree(root->firstchild);PrintBTree(root->rightsib);}// cout<<endl;
}void Menu()
{cout<<endl;cout<<"----------------主菜单-----------------"<<endl;//cout<<"输入1:-----双亲法创建一个一般树"<<endl;cout<<"输入2:-----树的前序遍历(递归)"<<endl;cout<<"输入3:-----树的后序遍历(递归)"<<endl;cout<<"输入4:-----树的前序遍历(非递归)//写出来了但未调试成功"<<endl;cout<<"输入5:-----树的后序遍历(非递归)//写出来了但未调试成功"<<endl;cout<<"输入6:-----树的层次遍历(非递归)"<<endl;cout<<"输入0:退出程序"<<endl;cout<<"---------------------------------------"<<endl;cout<<"请输入指令:"<<endl;
}void Menu2()
{cout<<"---------------------------------------"<<endl;cout<<"输入0:退出      输入1:继续"<<endl;cout<<"请输入指令:"<<endl;
}void preorder1(BTNode *T)//前序+递归
{if(T){cout<<T->data<<" ";preorder1(T->firstchild);preorder1(T->rightsib);}
}void preorder2(BTNode *T)//前序pre非递归2
{BTNode *p,*q;p=T;q=new BTNode;stack<BTNode*>S;S.push(p);while(!S.empty()){q=S.top();cout<<q->data<<" ";S.pop();if(p->rightsib)S.push(p->rightsib);if(p->firstchild)S.push(p->firstchild);}}void inorder1(BTNode *T)//树后根递归(中序)
{if(T){inorder1(T->firstchild);cout<<T->data<<" ";inorder1(T->rightsib);}
}void inorder2(BTNode *T)//后根非递归
{stack<BTree>S;BTNode *p,*q;p=T;//根指针q=new BTNode;p=new BTNode;while(p||!S.empty())//有一个非空{if(p)//长子不为空,一直走长子{S.push(p);//根指针进站p=p->firstchild;}else//左走到底,输出,此时p指向右兄弟{q=S.top();cout<<q->data<<" ";S.pop();q=S.top();p=q->rightsib;}}
}void levelorder(PTree T)
{int i;for(i=0;i<T.count;i++)cout<<T.node[i].data<<" ";cout<<endl;
}int main()
{int i=0,c1,c2;PTree T;BTNode *Tree;init_ptree(&T);// loop;//???cout<<"----------------请创建一棵树-----------------"<<endl;cout<<"建立一般树,依次输入各结点情况:"<<endl;cout<<"输入方式:双亲数据,整型数据(第一个结点双亲为-1,最后以-1结束)"<<endl;cout<<"例子:-1,1 1,3"<<endl;T=CreateTree(T);Tree=chang(T);cout<<"一般树转换成二叉树后先序输出:"<<endl;PrintBTree(Tree);cout<<endl;getchar();while(c2!=0){Menu();cin>>c1;switch(c1){case 2:cout<<"树的前序遍历(递归)"<<endl;preorder1(Tree);break;case 3:cout<<"树的后序遍历(递归)"<<endl;inorder1(Tree);break;case 4:cout<<"树的前序遍历(非递归)"<<endl;preorder2(Tree);break;case 5:cout<<"树的后序遍历(非递归)"<<endl;inorder2(Tree);break;case 6:cout<<"树的层次遍历(非递归)"<<endl;levelorder(T);break;case 0:cout<<"感谢使用QAQ"<<endl;exit(1);break;}cout<<endl;Menu2();cin>>c2;}cout<<"感谢使用QAQ"<<endl;return 0;
}

(四)图型结构题目

  • 行车路线

这里是把大路和小路分开存储,最后取最小值min(大路,小路);
由于小路连续走疲劳度会加和平方,所以预先处理下小路。

#include <bits/stdc++.h>#define inf 0x3f3f3f3f //无穷大
using namespace std;
long long dl[505][505],xl[505][505];//邻接矩阵
long long dis1[505],dis2[505];
bool jl[505],vis[505];
int n,m;
void floyd()//预处理小路,使得小路最短
{for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){if(xl[i][j]>xl[i][k]+xl[k][j]&&xl[i][k]!=inf&&xl[k][j]!=inf)//i->j比i->k->j路长&&i->k,k->j均有路{xl[i][j]=xl[i][k]+xl[k][j];//i->j用i->k->j替换}}
}
int main()
{memset(xl,inf,sizeof(xl));memset(dl,inf,sizeof(dl));//cout<<endl;cout<<"===================================欢迎使用========================================="<<endl;cout<<endl;cout<<"请分别输入路口和道路的个数:"<<endl;cin>>n>>m;//n个路口,m道路cout<<"请分别输入"<<m<<"个道路"<<"(道路类型(0大路/1小路)  路口1  路口2  路口长度):"<<endl;for(int i=1;i<=m;i++){int a,b,c,d;cin>>a>>b>>c>>d;//a类型 [b,c] d长度if(a==1&&xl[b][c]>d){//小路,目前d小xl[b][c]=xl[c][b]=d;//取d}else if(a==0&&dl[b][c]>d){//大路,目前d小dl[b][c]=dl[c][b]=d;//取d}}floyd();//初始化起点memset(dis1,inf,sizeof(dis1));memset(dis2,inf,sizeof(dis2));queue<int>q;dis1[1]=dis2[1]=0;//小路和大路分别存储比较q.push(1);vis[1]=1;//起点while(!q.empty())//队列不为空{int now=q.front();q.pop();vis[now]=0;for(int i=1;i<=n;i++){long long v=dl[now][i];if(dis1[i]>dis1[now]+v)//大路加大路{dis1[i]=dis1[now]+v;if(vis[i])continue;vis[i]=1;q.push(i);}if(dis1[i]>dis2[now]+v)//大路加小路{dis1[i]=dis2[now]+v;if(vis[i])continue;vis[i]=1;q.push(i);}if(xl[now][i]<1e10)//没懂?{v=xl[now][i]*xl[now][i];//由于xl已经处理过,直接平方就行if(dis2[i]>dis1[now]+v)//小路加大路{dis2[i]=dis1[now]+v;if(vis[i])continue;vis[i]=1;q.push(i);}}}}cout<<"==================================QAQ感谢使用============================================"<<endl;cout<<"最小疲劳度为:"<<endl;cout<<min(dis1[n],dis2[n])<<endl;return 0;}
/*
样例18 10
1 1 2 2
0 1 3 3
1 2 6 4
0 2 3 2
0 3 4 3
0 4 5 6
1 5 6 4
1 5 7 2
0 6 8 1
1 7 8 3
*/

(五)查找、排序、文件

  • 二叉排序树
#include <bits/stdc++.h>using namespace std;struct student
{char num[6];int grade;
};
typedef student ElemType;
typedef struct BSTNode
{ElemType data;struct BSTNode *lchild,*rchild;
}BSTNode,*BSTree;//全局变量
BSTree pre=NULL;
int n=0;int found(BSTree T,char ch[])//匹配
{BSTree p=T;while(p){if(strcmp(p->data.num,ch)==0)//姓名相等{return 1;}else{if(strcmp(p->data.num,ch)>0)//前者大{pre=p;p=p->lchild;}//查左子树else//前者小,找大的{pre=p;p=p->rchild;}}}return 0;
}void insertChild(BSTree &T,ElemType data)
{BSTree p;if(found(T,data.num)==0)//没有一样的{p=new BSTNode;p->data=data;p->rchild=p->lchild=NULL;if(!T)//空树T=p;else if(strcmp(pre->data.num,p->data.num)>0)//前者大,找左子树{pre->lchild=p;//插左子树}else//插右子树{pre->rchild=p;}}
}void cindata(BSTree &T)//输入学生数据
{int i;T=NULL;ElemType data;cout<<"请输入学生数量:";cin>>n;for(i=1;i<=n;i++){cout<<"请输入第"<<i<<"个学生信息:"<<endl;cout<<"学号(char类型):"<<endl;cin>>data.num;cout<<"成绩:"<<endl;cin>>data.grade;insertChild(T,data);}cout<<"录入成功"<<endl;
}void InOrder(BSTree T)
{if(T){InOrder(T->lchild);cout<<T->data.num<<" "<<T->data.grade<<endl;InOrder(T->rchild);}
}int DeepBT(BSTree T)
{int depl,depr;if(!T)return 0;//出口else{depl=DeepBT(T->lchild);depr=DeepBT(T->rchild);if(depl>=depr)//左子树>=右子树return (depl+1);elsereturn (depr+1);}
}int leaf(BSTree T)
{if(!T)return 0;else if(!(T->lchild)&&!(T->rchild))return 1;elsereturn leaf(T->lchild)+leaf(T->rchild);
}int deletee(BSTree &T)//删除节点 重连左/右子树
{BSTree q,s;if((!T->lchild)&&(!T->rchild))//此时为叶子结点T=NULL;else if(!T->lchild)//左子树空{q=T;T=T->rchild;delete(q);}else if(!T->rchild)//右子树空{q=T;T=T->lchild;delete(q);}else //左右均不空{q=T;s=T->lchild;//转左子树while(s->rchild)//(左子树中)向右走向尽头{q=s;s=s->rchild;}strcpy(T->data.num,s->data.num);if(q!=T)q->rchild=s->lchild;elseq->lchild=s->lchild;delete(s);}cout<<"删除成功"<<endl;n--;return 1;
}int DeleteBT(BSTree &T,ElemType data)
{if(found(T,data.num)==0)cout<<"未找到该学生,请重新核对"<<endl;else{if(strcmp(T->data.num,data.num)==0)deletee(T);else if(strcmp(T->data.num,data.num)>0)//前者大return DeleteBT(T->lchild,data);elsereturn DeleteBT(T->rchild,data);}
}
void DELETE(BSTree &T)
{ElemType data;cout<<"请输入要删除的学生"<<endl;cin>>data.num;DeleteBT(T,data);
}
void INSERT(BSTree &T)
{ElemType data;cout<<"请输入新增学生信息:"<<endl;cout<<"学号(char类型)"<<endl;cin>>data.num;cout<<"成绩:"<<endl;cin>>data.grade;insertChild(T,data);n++;cout<<"插入成功"<<endl;
}void SEARCH(BSTree T)
{BSTree p=T;ElemType data;int f=0;cout<<"请输入待查询学生的学号:"<<endl;cin>>data.num;while(p){if(strcmp(p->data.num,data.num)==0){cout<<"查询记录如下:"<<endl;cout<<"学号:"<<p->data.num<<endl;cout<<"成绩:"<<p->data.grade<<endl;f=1;break;}else if(strcmp(p->data.num,data.num)>0)//前者大{pre=p;p=p->lchild;}else{pre=p;p=p->rchild;}}if(!f)cout<<"未查询到该学生!"<<endl;return;
}void GYBcout(BSTree &T)
{if(T){cout<<T->data.num;if(T->lchild||T->rchild)//有不为空的{// cout<<"(";GYBcout(T->lchild);if(T->rchild)cout<<",";GYBcout(T->rchild);cout<<")";}//cout<<")";}
}
void Menu()
{cout<<"------------二叉排序树操作系统------------"<<endl;cout<<"------(1)从键盘输入一组学生记录建立二叉排序树"<<endl;cout<<"------(2)中序遍历二叉排序树"<<endl;cout<<"------(3)求二叉排序树深度"<<endl;cout<<"------(4)求二叉排序树的所有节点数和叶子节点数"<<endl;cout<<"------(5)向二叉排序树插入一条学生记录"<<endl;cout<<"------(6)从二叉排序树中删除一条学生记录"<<endl;cout<<"------(7)从二叉排序树中查询一条学生记录"<<endl;cout<<"------(8)以广义表的形式输出二叉排序树"<<endl;cout<<"-------------------------------------------"<<endl;
}
void Menu2()
{cout<<"输入:0/退出系统  1/继续操作"<<endl;
}
int main()
{BSTree T=NULL;int option,ff,x;while(ff){Menu();cout<<"请输入操作:"<<endl;cin>>option;ff=1;switch(option){case 1:cindata(T);break;case 2:InOrder(T);break;case 3:{x=DeepBT(T);cout<<"深度为:"<<x<<endl;}break;case 4:{x=leaf(T);cout<<"所有节点:"<<n<<"叶子结点数:"<<x<<endl;}break;case 5:INSERT(T);break;case 6:DELETE(T);break;case 7:SEARCH(T);break;case 8:GYBcout(T);break;// case 0:ff=0;break;}cout<<endl;Menu2();cin>>ff;}cout << "----------------QAQ感谢使用---------------" << endl;return 0;
}

这里是归档:2020/12/25

数据结构--课程设计(归档)相关推荐

  1. 数据结构课程设计——机票售卖系统(C++)

    引言 这学期最后的数据结构课程设计需要我们完成一个简单的小程序,我选择了一个机票售卖系统,实现了一些基本的功能:因为时间给的比较短,又赶在复习周补课,所以并没有什么突出的地方,我就在这里聊聊我的代码实 ...

  2. 数据结构课程设计---最长公共子串

    数据结构课程设计,由用户输入两个字符串串X和Y,再由用户输入一个任意的字符串Z,实现以下功能: ①如果字符串Z是字符串X的子串,则显示Z在X中的位置并记录,如果字符串Z是字符串Y的子串,则显示Z在Y中 ...

  3. 设树采用孩子兄弟表示法存放.用类c语言设计算法计算树的高度.,(数据结构课程设计分类题目.doc...

    (数据结构课程设计分类题目 线性表 顺序表: 1.设有一元素为整数的线性表L=(a1,a2,a3,-,an),存放在一维数组A[N]中,设计一个算法,以表中an作为参考元素,将该表分为左.右两部分,其 ...

  4. c语言数据结构五子棋实验报告,数据结构课程设计-五子棋

    数据结构课程设计-五子棋 姓 名: 学 院: 计算机与通信学院 班 级: 通信工程 101 班 指导老师: 目录一.需求分析 31.1 开发背景 .32.2 功能简介 .3二.系统设计 42.1 函数 ...

  5. 数据结构迷宫代码_数据结构课程设计——迷宫求解(二)

    前言 接上文的介绍,本文将主要介绍如何生成随机迷宫,在网上找到的资源也比较多,这里我选取了随机 Prim 算法生成迷宫,选择这个算法的理由如下: 算法思想简单,易于实现 生成的迷宫比较自然,不会出现明 ...

  6. c语言小数表达式运算课程设计,数据结构课程设计表达式计算.doc

    数据结构课程设计表达式计算 福建农林大学计算机与信息学院 计算机类 课程设计报告 课程名称:算法与数据结构课程设计题目:表达式计算姓 名:系:数学系专 业:数学与应用数学年 级:学 号:指导教师:宁正 ...

  7. 数据结构课程设计:顺序结构、动态链表结构下的一元多项式的加法、减法、乘法的实现...

    原来做的数据结构课程设计,今天整理资料时偶然发现了,自己留着没啥意思,共享一下吧,互相交流学习 要求 设有一元多项式Am(x)和Bn(x). Am(x)=A0+A1x1+A2x2+A3x3+- +Am ...

  8. c语言数据结构课程设计停车场管理系统,数据结构课程设计报告停车场管理系统...

    <数据结构课程设计报告停车场管理系统>由会员分享,可在线阅读,更多相关<数据结构课程设计报告停车场管理系统(8页珍藏版)>请在人人文库网上搜索. 1.数据结构课程设计报告系 别 ...

  9. 学生搭配问题数据结构报告c语言,数据结构课程设计_学生搭配问题.doc

    数据结构课程设计_学生搭配问题 数据结构课程设计 题 目: 学生搭配问题 学 院: 班 级: 学 生 姓 名: 学 生 学 号: 指 导 教 师: 2012 年 12 月 3 日 课程设计任务书 姓名 ...

  10. C/C++《数据结构课程设计》任务书[2022-12-27]

    C/C++<数据结构课程设计>任务书[2022-12-27] <数据结构课程设计>任务书 一.任务总体安排: 班级 设计时间 地点 指导老师 21软件开发 17周每周一至周五五 ...

最新文章

  1. 实锤了!史上最惨的新浪程序员
  2. [zz]Ubuntu建立本地源实用案例
  3. javascript生成指定范围的随机整数
  4. ubuntu连接有线局域网后无法使用无线网卡上网
  5. 虚拟机VMware搭建代码环境
  6. golang实现四种排序(快速,冒泡,插入,选择)
  7. linux 安装docker
  8. isset,empty,is_null小知识
  9. [转载] Python中NumPy简介及使用举例
  10. [ZT]用CSC.exe来编译Visual C#的代码文件,解释CSC参数和开关的具体作用
  11. c语言程序关键字查询,C语言关键字大全(共32个)
  12. mac黑白打印和彩色打印
  13. 如何在电脑上给视频去水印
  14. easyx——c语言实时动画时钟
  15. win10没有声音(扬声器一直显示未插入)
  16. 开机自检(POST)
  17. 如何判断自己的IP是否为公网IP?
  18. WIN10极限清理 C盘空间
  19. 树莓派添加网络打印机
  20. typescript (简写Ts)

热门文章

  1. iOS:xxx referenced from
  2. python2和3切换_python2和python3切换
  3. google地图网页版_谷歌收录查询方法大全,如何让Google快速收录网页?
  4. 分布式和微服务区别_分布式、集群、微服务到底有啥区别?
  5. linux 搭建cloudreve win映射网络驱动器WebDav
  6. php 操作系统,PHP 处理文件和操作系统
  7. quartz java 实现_Quartz使用-入门使用(java定时任务实现)
  8. 用python画图的作品_中学教案-python绘图
  9. java书籍_腾讯大牛每天都要花一小时读的这11本java电子书籍,你还不看?
  10. android studio外接模拟器,Android Studio,使用外部模拟器作为生成app调试的模拟器