队列
MyDreamingCode
Life is not a bed of roses.
展开
-
二叉树的层次遍历(用队列来实现)
#include<stdio.h>#include<stdlib.h>#define MaxSize 50typedef char ElemType;typedef struct BTNode{ ElemType data; struct BTNode *left; struct BTNode *right;}BTNode,*BiTree;typedef struct Queue{ BTNode *data[MaxSize]; //注意这里的data要.原创 2021-11-16 20:36:36 · 730 阅读 · 1 评论 -
循环单链表创建队列
/*请设计一个队列,要求满足:1.初始时队列为空;2.入队时,允许增加队列占用空间;3.出队后,出队元素所占用的空间可重复使用,即整个队列所占用的空间值增不减;4.入队操作和出队操作的时间复杂度始终保持为O(1)*///想法:与顺序循环存储队列相似#include<stdio.h>#include<stdlib.h>typedef int ElemType;typedef struct LNode{ ElemType data; struct LNode *next.原创 2021-09-14 07:19:32 · 315 阅读 · 0 评论 -
利用两个栈来模拟实现队列
/*利用两个栈S1、S2来模拟一个队列*/#include<stdio.h>#define MaxSize 10typedef int ElemType;typedef struct{ ElemType data[MaxSize]; int top;}SqStack;void InitStack(SqStack &S){ S.top = -1;}bool EmptyStack(SqStack S){ if(S.top == -1) return tr.原创 2021-09-14 07:19:16 · 272 阅读 · 0 评论 -
队列-链式存储
#include<stdio.h>#include<stdlib.h>typedef int ElemType;typedef struct LNode{ ElemType data; struct LNode *next;}LNode;typedef struct Queue{ LNode *front,*rear;}Queue;void InitQueue(Queue &Q){ Q.front = Q.rear = (LNode*)malloc.原创 2021-09-14 07:19:06 · 42 阅读 · 0 评论 -
实现队列中的元素逆置(使用栈+队列)
/*Q是一个队列,S是一个空栈,实现将队列中的元素逆置的算法*/#include<stdio.h>#define MaxSize 10typedef int ElemType;typedef struct{ ElemType data[MaxSize]; int front,rear;}Queue;typedef struct{ ElemType data[MaxSize]; int top;}SqStack;void InitStack(SqStack &S.原创 2021-09-14 07:18:57 · 6407 阅读 · 0 评论 -
循环队列-顺序存储
#include<stdio.h>#define MaxSize 3typedef int ElemType;typedef struct{ int front; int rear; ElemType data[MaxSize];}Queue;void InitQueue(Queue &Q){ Q.front = Q.rear = 0;}bool EmptyQueue(Queue Q){ if(Q.front == Q.rear) return tr.原创 2021-09-14 07:18:40 · 61 阅读 · 0 评论 -
队列-顺序存储
#include<stdio.h>#define maxSize 10typedef int ElemType;typedef struct{ ElemType data[maxSize]; int front; int rear;}SqQueue;void InitQueue(SqQueue &Q){ Q.rear = Q.front = 0;}bool EmptyQueue(SqQueue Q){ if(Q.rear==Q.front) retu.原创 2021-09-14 07:19:40 · 37 阅读 · 0 评论