链式队列的基本操作与实现
来源:互联网 发布:转置矩阵与原矩阵相乘 编辑:程序博客网 时间:2024/04/30 03:48
#include <stdio.h>#include <stdbool.h>#include <stdlib.h>#include <iostream>typedef int ElementType;//定义结点typedef struct LinkNode{ ElementType data; struct LinkNode* next;} *StackNode, *QueueNode;//定义队列typedef struct { LinkNode *front, *rear;} LinkQueue;//初始化队列LinkQueue* InitQueue(LinkQueue* L){ printf("初始化队列\n"); L = (LinkQueue*)malloc(sizeof(LinkQueue)); //L->rear = L->front = NULL; L->front = L->rear = (LinkNode*)malloc(sizeof(LinkNode)); L->front->next = NULL; return L;}//判断队列是否为空bool IsQueueEmpty(LinkQueue* L){ if (L->front == L->rear){ printf("队列为空\n"); return false; } return true;}//入队LinkQueue* EnQueue(LinkQueue* Queue, ElementType data){ LinkNode* L = (LinkNode*)malloc(sizeof(LinkNode)); L->data = data; L->next = NULL; Queue->rear->next = L; Queue->rear = L; printf("入队元素为:%d\n", Queue->rear->data); return Queue;}//出队LinkQueue* DeQueue(LinkQueue* L){ if (IsQueueEmpty(L) == false){ printf(":所以不能出队!\n"); return NULL; } printf("出队元素是:%d\n", L->front->next->data); //用这一句就够了 //L->front = L->front->next; //为了严谨,用一下语句 LinkNode* node = (LinkNode*)malloc(sizeof(LinkNode)); node = L->front->next; //printf("L->front=%d\n", L->front->data); L->front->next = node->next; //printf("L->front=%d\n", L->front->data); if (L->rear == node) L->front = L->rear; //printf("对头元素是:%d\n", L->front->next->data); free(node); return L;}// int main(void){// LinkQueue* Queue;// Queue = InitQueue(Queue);// if (IsQueueEmpty(Queue) == true)// printf("初始化为空成功");// EnQueue(Queue, 1);EnQueue(Queue, 2);// EnQueue(Queue, 3);EnQueue(Queue, 4);EnQueue(Queue, 5);// DeQueue(Queue);DeQueue(Queue);// DeQueue(Queue);DeQueue(Queue);DeQueue(Queue);// system("pause");// return 0;// }
阅读全文
0 0
- 链式队列的基本操作与实现
- 链式队列的基本操作实现c++
- 【队列】链式结构实现队列的基本操作
- 链式队列的基本操作
- 链式栈的基本操作与实现
- 链式队列的操作实现
- 链式队列基本操作
- 链式队列基本操作
- 【数据结构】链式队列的基本操作
- 链式队列的基本操作(配图)
- 循环队列与链式队列的实现
- 队列的实现与基本操作
- 队列的实现与基本操作
- 链式队列8种操作的实现
- 队列操作的实现-链式存储
- 循环队列和链式队列的基本操作1
- 链式队列基本操作总结
- 队列的链式存储结构与操作
- SVM1
- arcgis api for javascript graphiclayer dojo框架下画图图层的显示与清除
- 【H.264/AVC视频编解码技术详解】三. H.264简介
- 【脚本学习】shell脚本入门-eval和crontab
- 中小企业需注意的2个数据中心安全问题
- 链式队列的基本操作与实现
- 深度学习基础之-梯度弥散和梯度爆炸及解决办法
- 基于NVIDIA TEGRA系列板卡的硬件解码及视频推流
- opencv hog源码解析
- 1.1 数组和链表:169.Majority Element (Leetcode)
- Gson的使用并附上Utils
- 记一次网络故障的解决
- 切换Fragment显示
- 【转】对Linux内核中进程上下文和中断上下文的理解