编译原理 1、读取所有的输入的文本,存入一个二维数组。(数组的宽度固定) 2、对二维数组一行行进行处理 3、对文本进行操作的时候,创建两个临时字符数组,一个存储变量名,一个存储常量。 对某行进行遍历的时候,倘若碰到字母,就读完该单词并存储到临时数组里,进行基本字判断后输出。 光标往后移动该单词的长度后,继续循环。(比如读到的是end,那么我该行的光标就要+3,然后继续循环) 倘若读到数字也是一样,只是不需要判断基本字,所以更为简单。
标签: 编译原理
上传时间: 2017-06-20
上传用户:lbxxx
1.学会二叉树这一数据结构的用法,掌握二叉树的存储结构,包括二叉树顺序存储结构和链式存储结构。 2.熟练掌握二叉树与广义表之间的相互转换方法。 3.熟练掌握二叉树的先序、中序、后序,递归与非递归遍历算法。 4.学会二叉树线索化方法,并掌握线索二叉树的存储结构。 5.熟练掌握线索二叉树的先序、中序、后序的遍历算法。
标签: 树
上传时间: 2017-12-03
上传用户:mxs1234
学生信息管理系统 管理系统中有五个要求:输入 查找 修改 插入 删除 存储 (1) 输入要求:能够通过键盘输入和文件输入两种 (2) 查找要求:能够根据学生号查找单个学生的信息,也可以遍历所有学生信息 (3) 修改要求:能够根据学生号修改单个学生所有信息 (4) 插入要求:能够实现头插和尾插 (5) 删除要求:能够根据学生号删除单个学生信息 (6) 存储要求:通过链表存储所有信息
标签: 信息管理系统
上传时间: 2017-12-25
上传用户:phc62
#include <iostream> #include <stdio.head> #include <stdlib.head> #include <string.head> #define ElemType int #define max 100 using namespace std; typedef struct node1 { ElemType data; struct node1 *next; }Node1,*LinkList;//链栈 typedef struct { ElemType *base; int top; }SqStack;//顺序栈 typedef struct node2 { ElemType data; struct node2 *next; }Node2,*LinkQueue; typedef struct node22 { LinkQueue front; LinkQueue rear; }*LinkList;//链队列 typedef struct { ElemType *base; int front,rear; }SqQueue;//顺序队列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 //1.采用链式存储实现栈的初始化、入栈、出栈操作。 LinkList CreateStack()//创建栈 { LinkList top; top=NULL; return top; } bool StackEmpty(LinkList s)//判断栈是否为空,0代表空 { if(s==NULL) return 0; else return 1; } LinkList Pushead(LinkList s,int x)//入栈 { LinkList q,top=s; q=(LinkList)malloc(sizeof(Node1)); q->data=x; q->next=top; top=q; return top; } LinkList Pop(LinkList s,int &e)//出栈 { if(!StackEmpty(s)) { printf("栈为空。"); } else { e=s->data; LinkList p=s; s=s->next; free(p); } return s; } void DisplayStack(LinkList s)//遍历输出栈中元素 { if(!StackEmpty(s)) printf("栈为空。"); else { wheadile(s!=NULL) { cout<<s->data<<" "; s=s->next; } cout<<endl; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 //2.采用顺序存储实现栈的初始化、入栈、出栈操作。 int StackEmpty(int t)//判断栈S是否为空 { SqStack.top=t; if (SqStack.top==0) return 0; else return 1; } int InitStack() { SqStack.top=0; return SqStack.top; } int pushead(int t,int e) { SqStack.top=t; SqStack.base[++SqStack.top]=e; return SqStack.top; } int pop(int t,int *e)//出栈 { SqStack.top=t; if(!StackEmpty(SqStack.top)) { printf("栈为空."); return SqStack.top; } *e=SqStack.base[s.top]; SqStack.top--; return SqStack.top; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 //3.采用链式存储实现队列的初始化、入队、出队操作。 LinkList InitQueue()//创建 { LinkList head; head->rear=(LinkQueue)malloc(sizeof(Node)); head->front=head->rear; head->front->next=NULL; return head; } void deleteEle(LinkList head,int &e)//出队 { LinkQueue p; p=head->front->next; e=p->data; head->front->next=p->next; if(head->rear==p) head->rear=head->front; free(p); } void EnQueue(LinkList head,int e)//入队 { LinkQueue p=(LinkQueue)malloc(sizeof(Node)); p->data=e; p->next=NULL; head->rear->next=p; head->rear=p; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 //4.采用顺序存储实现循环队列的初始化、入队、出队操作。 bool InitQueue(SqQueue &head)//创建队列 { head.data=(int *)malloc(sizeof(int)); head.front=head.rear=0; return 1; } bool EnQueue(SqQueue &head,int e)//入队 { if((head.rear+1)%MAXQSIZE==head.front) { printf("队列已满\n"); return 0; } head.data[head.rear]=e; head.rear=(head.rear+1)%MAXQSIZE; return 1; } int QueueLengthead(SqQueue &head)//返回队列长度 { return (head.rear-head.front+MAXQSIZE)%MAXQSIZE; } bool deleteEle(SqQueue &head,int &e)//出队 { if(head.front==head.rear) { cout<<"队列为空!"<<endl; return 0; } e=head.data[head.front]; head.front=(head.front+1)%MAXQSIZE; return 1; } int gethead(SqQueue head)//得到队列头元素 { return head.data[head.front]; } int QueueEmpty(SqQueue head)//判断队列是否为空 { if (head.front==head.rear) return 1; else return 0; } void travelQueue(SqQueue head)//遍历输出 { wheadile(head.front!=head.rear) { printf("%d ",head.data[head.front]); head.front=(head.front+1)%MAXQSIZE; } cout<<endl; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 //5.在主函数中设计一个简单的菜单,分别测试上述算法。 int main() { LinkList top=CreateStack(); int x; wheadile(scanf("%d",&x)!=-1) { top=Pushead(top,x); } int e; wheadile(StackEmpty(top)) { top=Pop(top,e); printf("%d ",e); }//以上是链栈的测试 int top=InitStack(); int x; wheadile(cin>>x) top=pushead(top,x); int e; wheadile(StackEmpty(top)) { top=pop(top,&e); printf("%d ",e); }//以上是顺序栈的测试 LinkList Q; Q=InitQueue(); int x; wheadile(scanf("%d",&x)!=-1) { EnQueue(Q,x); } int e; wheadile(Q) { deleteEle(Q,e); printf("%d ",e); }//以上是链队列的测试 SqQueue Q1; InitQueue(Q1); int x; wheadile(scanf("%d",&x)!=-1) { EnQueue(Q1,x); } int e; wheadile(QueueEmpty(Q1)) { deleteEle(Q1,e); printf("%d ",e); } return 0; }
上传时间: 2018-05-09
上传用户:123456..
任务1:以算法5.3创建二叉树的存储结构,树的具体形态自定。 任务2:对任务1中的二叉树T分别实现先序、中序、后序遍历(递归实现)和中序遍历的非递归实现以及层序遍历; 任务3:统计1中二叉树T的结点总数、叶子结点总数以及T的高度; 任务4:交换1中二叉树T的所有结点的左右子树,并对交换后的二叉树重新进行中序遍历(和任务2中的中序遍历结果对比,你有什么发现?)。
上传时间: 2018-07-03
上传用户:MOOMWHITE
用邻接矩阵的方式实现图,包括图的创建、查询、插入删除、广度遍历和深度遍历
标签: 数据结构
上传时间: 2018-09-08
上传用户:yhrdecc
使用两个栈分别存放操作符和操作数,依次读取是操作数如操作数栈,是运算符入运算符栈,比较优先级,求值。 计算后缀:从左到右遍历后缀表达式,遇到操作数,放进栈,遇到操作符,栈顶两个数出栈,进行运算,运算结果放进栈,直到读完后缀表达式。 计算前缀:从左到右遍历前缀表达式,遇到操作符,放进栈,遇到操作数,查看栈顶,栈顶为操作符,放进栈,栈顶为操作数,取出栈顶操作数和操作符,进行运算,运算后继续判断栈顶的情况 转化为后缀:从左到右遍历中缀表达式,遇到操作数,输出,遇到操作符,栈顶操作符优先级小于等于当前操作符的优先级,进栈,否则,弹出栈顶优先级大于等于当前操作符的操作符,当前操作符进栈。 转化为前缀:从右到左遍历中缀表达式,遇到操作数,输出,遇到操作符,栈顶操作符优先级小于当前操作符的优先级,进栈,否则,弹出栈顶优先级大于当前操作符的操作符,当前操作符进栈
上传时间: 2019-04-15
上传用户:1431313
二叉树的前序、中序、后序遍历的递归和非递归算法
上传时间: 2020-04-10
上传用户:renwwei1986
#include<stdio.h> #define TREEMAX 100 typedef struct BT { char data; BT *lchild; BT *rchild; }BT; BT *CreateTree(); void Preorder(BT *T); void Postorder(BT *T); void Inorder(BT *T); void Leafnum(BT *T); void Nodenum(BT *T); int TreeDepth(BT *T); int count=0; void main() { BT *T=NULL; char ch1,ch2,a; ch1='y'; while(ch1=='y'||ch1=='y') { printf("\n"); printf("\n\t\t 二叉树子系统"); printf("\n\t\t*****************************************"); printf("\n\t\t 1---------建二叉树 "); printf("\n\t\t 2---------先序遍历 "); printf("\n\t\t 3---------中序遍历 "); printf("\n\t\t 4---------后序遍历 "); printf("\n\t\t 5---------求叶子数 "); printf("\n\t\t 6---------求结点数 "); printf("\n\t\t 7---------求树深度 "); printf("\n\t\t 0---------返 回 "); printf("\n\t\t*****************************************"); printf("\n\t\t 请选择菜单号 (0--7)"); scanf("%c",&ch2); getchar(); printf("\n"); switch(ch2) { case'1': printf("\n\t\t请按先序序列输入二叉树的结点:\n"); printf("\n\t\t说明:输入结点(‘0’代表后继结点为空)后按回车。\n"); printf("\n\t\t请输入根结点:"); T=CreateTree(); printf("\n\t\t二叉树成功建立!\n");break; case'2': printf("\n\t\t该二叉树的先序遍历序列为:"); Preorder(T);break; case'3': printf("\n\t\t该二叉树的中序遍历序列为:"); Inorder(T);break; case'4': printf("\n\t\t该二叉树的后序遍历序列为:"); Postorder(T);break; case'5': count=0;Leafnum(T); printf("\n\t\t该二叉树有%d个叶子。\n",count);break; case'6': count=0;Nodenum(T); printf("\n\t\t该二叉树总共有%d个结点。\n",count);break; case'7': printf("\n\t\t该树的深度为:%d",TreeDepth(T)); break; case'0': ch1='n';break; default: printf("\n\t\t***请注意:输入有误!***"); } if(ch2!='0') { printf("\n\n\t\t按【Enter】键继续,按任意键返回主菜单!\n"); a=getchar(); if(a!='\xA') { getchar(); ch1='n'; } } } } BT *CreateTree() { BT *t; char x; scanf("%c",&x); getchar(); if(x=='0') t=NULL; else { t=new BT; t->data=x; printf("\n\t\t请输入%c结点的左子结点:",t->data); t->lchild=CreateTree(); printf("\n\t\t请输入%c结点的右子结点:",t->data); t->rchild=CreateTree(); } return t; } void Preorder(BT *T) { if(T) { printf("%3c",T->data); Preorder(T->lchild); Preorder(T->rchild); } } void Inorder(BT *T) { if(T) { Inorder(T->lchild); printf("%3c",T->data); Inorder(T->rchild); } } void Postorder(BT *T) { if(T) { Postorder(T->lchild); Postorder(T->rchild); printf("%3c",T->data); } } void Leafnum(BT *T) { if(T) { if(T->lchild==NULL&&T->rchild==NULL) count++; Leafnum(T->lchild); Leafnum(T->rchild); } } void Nodenum(BT *T) { if(T) { count++; Nodenum(T->lchild); Nodenum(T->rchild); } } int TreeDepth(BT *T) { int ldep,rdep; if(T==NULL) return 0; else { ldep=TreeDepth(T->lchild); rdep=TreeDepth(T->rchild); if(ldep>rdep) return ldep+1; else return rdep+1; } }
上传时间: 2020-06-11
上传用户:ccccy
60个Android开发精典案例 Android软件源码:2-1(Activity生命周期)3-1(Button与点击监听器)3-10-1(列表之ArrayAdapter适配)3-10-2(列表之SimpleAdapter适配)3-11(Dialog对话框)3-12-5(Activity跳转与操作)3-12-6(横竖屏切换处理)3-3(ImageButton图片按钮)3-4(EditText文本编辑)3-5(CheckBox与监听)3-6(RadioButton与监听)3-7(ProgressBar进度条)3-8(SeekBar 拖动条)3-9(Tab分页式菜单)4-10(可视区域)4-11-1(Animation动画)4-11-2-1(动态位图)4-11-2-2(帧动画)4-11-2-3(剪切图动画)4-13(操作游戏主角)4-14-1(矩形碰撞)4-14-2(圆形碰撞)4-14-4(多矩形碰撞)4-14-5(Region碰撞检测)4-15-1(MediaPlayer音乐)4-15-2(SoundPool音效)4-16-1(游戏保存之SharedPreference)4-16-2(游戏保存之Stream)4-3(View游戏框架)4-4(SurfaceView游戏框架)4-7-1(贝塞尔曲线)4-7-2(Canvas画布)4-8(Paint画笔)4-9(Bitmap位图渲染与操作)5-1(飞行射击游戏实战)6-1(360°平滑游戏摇杆)6-10-1(Socket协议)6-10-2(Http协议)6-11(本地化与国际化)6-2(多触点缩放位图)6-3(触屏手势识别)6-4(加速度传感器)6-5(9patch工具)]6-6(截屏)6-8(游戏视图与系统组件)6-9(蓝牙对战游戏)7-10-1(遍历Body)7-10-2(Body的m_userData)7-11(为Body施加力)7-12(Body碰撞监听)7-13-1(距离关节)7-13-2(旋转关节)7-13-3(齿轮关节)7-13-4(滑轮关节)7-13-5-1(通过移动关节移动Body)7-13-5-2(通过移动关节绑定两个Body动作)7-13-6(鼠标关节-拖拽Body)7-14(AABB获取Body)7-4(Box2d物理世界)7-5在物理世界中添加矩形)7-7(添加自定义多边形)7-9(在物理世界中添加圆形)8-1(迷宫小球)8-2(堆房子)
标签: android
上传时间: 2021-11-30
上传用户:trh505