1.学会二叉树这一数据结构的用法,掌握二叉树的存储结构,包括二叉树顺序存储结构和链式存储结构。 2.熟练掌握二叉树与广义表之间的相互转换方法。 3.熟练掌握二叉树的先序、中序、后序,递归与非递归遍历算法。 4.学会二叉树线索化方法,并掌握线索二叉树的存储结构。 5.熟练掌握线索二叉树的先序、中序、后序的遍历算法。
标签: 树
上传时间: 2017-12-03
上传用户:mxs1234
#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..
矩阵运算包含加减乘三元组顺序表存储的c语言
上传时间: 2015-03-22
上传用户:evil
题目:稀疏矩阵是指那些多数元素为0的矩阵.利用稀疏特点进行存储和计算可以大大节省存储空间,提高计算效率.实现一个能进行稀疏矩阵基本运算的运算器.基本要求:以带行逻辑连接信息的3元组顺序表表示稀疏矩阵,实现两个矩阵相加,相减和相乘的运算.矩阵的输入形式采用3元组表示,而运算结果的矩阵则以通常的阵列形式列出.概要设计:1.以带行逻辑连接信息的3元组顺序表表示稀疏矩阵2.本程序包含2个模块:(1) 各集合定义模块(2) 主程序模块
上传时间: 2013-12-18
上传用户:love_stanford
线性数据结构算法实现 栈的顺序和链式存储存表示与基本算法的实现; 队列的链式存储表示与基本操作算法实现
上传时间: 2014-01-25
上传用户:1101055045
掌握栈与队列的数据类型描述及特点; 2)掌握栈的顺序和链式存储存表示与基本算法的实现; 3)掌握队列的链式存储表示与基本操作算法实现 4) 掌握栈与队列在实际问题中的应用和基本编程技巧 5)按照实验题目要求,独立完成实际程序的编写编写、调试和运行,并通过用例数的运行过程抓获相关屏面验证程序设计的正确性;
上传时间: 2013-12-20
上传用户:wxhwjf
1)掌握栈与队列的数据类型描述及特点; 2)掌握栈的顺序和链式存储存表示与基本算法的实现; 3)掌握队列的链式存储表示与基本操作算法实现 4) 掌握栈与队列在实际问题中的应用和基本编程技巧
上传时间: 2013-12-30
上传用户:ouyangtongze
顺序表是线性表的一种最简单的存储结构。大家多多支持
上传时间: 2016-04-12
上传用户:lijinchuan
描述了队列的基本操作 它的存储结构采取的顺序形式
上传时间: 2013-12-20
上传用户:yuchunhai1990
掌握线形表的基本操作在顺序和链表这两种存储结构上的实验,尤其链表的操作和应用作为重点。
上传时间: 2014-01-07
上传用户:zyt