栈与队列--创建栈/队列
来源:互联网 发布:安卓改定位软件 编辑:程序博客网 时间:2024/05/18 03:20
数组栈
完成Stack CreateStack(int MaxElements)函数,该函数创建一个栈,MaxElements为与分配的栈空间大小(栈可用空间为Array[0,…MaxElements-1])。
typedef int ElemType;struct StackRecord;typedef struct StackRecord *Stack;struct StackRecord{ int Capacity; //栈容量 int Top; //栈顶,初始为1 ElemType *Array;};Stack CreateStack(int MaxElements){ Stack s=(StackRecord *)malloc(sizeof(StackRecord)); s‐>Top=‐1; s‐>Capacity=MaxElements; s‐>Array=(ElemType *)malloc(MaxElements*sizeof(ElemType)); return s;}
链栈
完成Stack CreateStack(void)函数,该函数创建一个栈(空栈,带头结点),并返回栈指针。
typedef int ElemType;struct Node;typedef struct Node * PtrToNode;typedef PtrToNode Stack;struct Node{ ElemType data; PtrToNode next;};Stack CreateStack(void){ Stack top; Node *s; top=NULL; s=(Node *)malloc(sizeof(Node)); s‐>next=top; top=s; return top;}
数组队列
完成Queue CreateQueue(int MaxElements)函数,该函数创建一个基于数组的队列,并返回队列指针,其中MaxElements为预分配的数组单元数。
typedef int ElemType;struct QueueRecord;typedef struct QueueRecord * Queue;struct QueueRecord{ int Capacity; //队列总容量 int Front; //队首 初始值为0 int Rear; //队尾,初始值为1 int Size; //队列中数据数,初始值为0 ElemType *Array;};Queue CreateQueue(int MaxElements){ Queue s=(QueueRecord *)malloc(sizeof(QueueRecord)); s‐>Front=0; s‐>Rear=‐1; s‐>Capacity=MaxElements; s‐>Array=(ElemType *)malloc(MaxElements*sizeof(ElemType)); return s;}
链队列
完成Queue CreateQueue(void)函数,该函数创建一个基于链表的队列,并返回队列指针,创建的链表队列不带头节点。
typedef int ElemType;struct node;typedef struct node Node;struct queue;typedef struct queue * Queue;struct node{ ElemType data; Node * next;};struct queue{ Node * front; //队首 Node * rear; //队尾 int size; //队列中数据数};Queue CreateQueue(void){ Queue q; q=(queue *)malloc(sizeof(queue)); q‐>front=NULL; q‐>rear=NULL; q‐>size=0; return q;}
0 0
- 栈与队列--创建栈/队列
- 栈与队列->队列
- 栈、队列与优先队列
- 栈与队列-单调栈,单调队列
- 7.7 栈与队列-队列及其操作
- 栈、队列与优先队列的认识
- 数据结构与算法--栈、队列(队列)
- 栈与队列
- 堆与栈 队列
- 队列与栈
- 16 栈与队列
- 栈与队列
- 【数据结构】栈与队列
- 栈与队列
- 栈与队列....
- 栈与队列
- 栈与队列专题
- 栈与队列
- 2016.6.28笔记(1)-MVC基础知识
- web项目改名后无法通过新名称访问
- PCI9054 突发模式数据传输 (burst mode data transfer )
- Java web 乱码
- BCGControlBar使用入门指南
- 栈与队列--创建栈/队列
- TortoiseGit工具安装
- oracle 递归使用
- linux学习三部曲
- 如何利用python爬虫技术将百度贴吧上面的帖子名称爬取下来
- mongodb的聚合函数的$redact方法运用。
- Django 基础
- linux下软件的安装与卸载方法
- 【论文笔记】Text-Recognition_简略版_201606