当前位置: 首页 > news >正文

做网站都注意哪些东西百度营销登录入口

做网站都注意哪些东西,百度营销登录入口,最基本的网络营销站点,转笔教学网站为什么80%的码农都做不了架构师?>>> 数据结构与算法 3.4 队列ADT 像栈一样,队列(queue)也是表。然而,使用队列时插入在一端进行而删除则在另一端进行。 3.4.1 队列模型 队列的基本操作是Enqueue&#xff0…

为什么80%的码农都做不了架构师?>>>   hot3.png

数据结构与算法 3.4 队列ADT

像栈一样,队列(queue)也是表。然而,使用队列时插入在一端进行而删除则在另一端进行。

3.4.1 队列模型

队列的基本操作是Enqueue(入队),它是在表的末端(或叫队尾(rear))插入一个元素,还有一个Dequeue(出队),它是删除(或返回)在表的开头(叫做队头(front))的元素。
图3-56显示一个队列的抽象模型:

              +------------+Dequeue(Q)  |            |   Enqueue(Q, X)
<----------   |   Queue Q  |  <-------------|            |+------------+图3-56 队列模型  

3.4.2 队列的链表实现

我们讨论队列的链表实现,对于每一个队列数据结构,我们需要保留一个Front指针与一个Rear指针用于标记队头及队尾。 图3-57显示一个队列的双向链表实现示例:

+----------+     +---------+     +---------+     +---------+
|\0|Head|68|---> |58| A |88|---> |68| B |99|---> |88| C |\0|
+----------+     +---------+     +---------+     +---------+↑                               ↑                           +---------+                     +---------+     |  Front  |                     |   Rear  | +---------+                     +---------+图3-57 队列双向链表实现

头文件 - queue.h

#include <stdio.h>
#include <stdlib.h>
#include "../../fatal.h"typedef int ElementType;struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode Queue;
typedef PtrToNode Position;
typedef PtrToNode Front;
typedef PtrToNode Rear;// 创建队列
Queue CreateQueue(Queue);
// 入队
void Enqueue(Queue, ElementType);
// 出队
ElementType Dequeue(Queue);
// 输出队列
void PrintQueue(Queue);

源文件 - queue.c

#include "queue.h"// 创建新的节点
static Position NewNode(void);
// 是否空队列
static int IsEmptyQueue(Queue);
// 队列清空
static void MakeEmptyQueue(Queue);struct Node {ElementType Element;PtrToNode Next;PtrToNode Prev;
};// 队头Front
static Front QueueFront = NULL;
// 队尾Rear
static Rear  QueueRear  = NULL;/*** 创建新的节点* @return */
static Position NewNode() {return (Position)malloc(sizeof(struct Node));
}/*** 是否空队列* @param Q* @return */
static int IsEmptyQueue(Queue Q) {return Q->Next == NULL;
}/*** 队列清空* @param Q*/
static void MakeEmptyQueue(Queue Q) {Position P, Tmp;P = Q->Next;while (P != NULL) {Tmp = P->Next;free(P);P = Tmp;}Q->Next	= NULL;QueueFront = Q;QueueRear  = Q;
}/*** 创建队列* @param Q* @return */
Queue CreateQueue(Queue Q) {if (Q != NULL) {MakeEmptyQueue(Q);}Q = NewNode();if (Q == NULL) {FatalError("Out of memory!");}Q->Next = NULL;Q->Prev = NULL;QueueFront = Q;QueueRear  = Q;return Q;
}/*** 入队* @param Q* @param */
void Enqueue(Queue Q, ElementType X) {Position TmpCell = NewNode();if (TmpCell == NULL) {FatalError("Out of memory!");}if (IsEmptyQueue(Q)) {QueueRear = TmpCell;} else {Q->Next->Prev = TmpCell;}TmpCell->Element= X;TmpCell->Next   = Q->Next;TmpCell->Prev   = Q;Q->Next   = TmpCell;QueueFront= TmpCell;
}/*** 出队* @param Q* @return */
ElementType Dequeue(Queue Q) {if (IsEmptyQueue(Q)) {FatalError("Queue is empty!");}Position Prev = QueueRear->Prev;ElementType X = QueueRear->Element;Prev->Next= NULL;free(QueueRear);QueueRear = Prev;return X;
}/*** 输出队列* @param Q*/
void PrintQueue(Queue Q) {if (IsEmptyQueue(Q)) {FatalError("Queue is empty!");}Position P = Q->Next;while (P != NULL) {printf("|%x|%d|%x|", P->Prev, P->Element, P->Next);P = P->Next;if (P != NULL) {printf("-->");}}printf("\n");
}

调用示例

#include "ext/s16/queue.h"int main(int argc, char** argv) {Queue Q = CreateQueue(NULL);Enqueue(Q, 5);Enqueue(Q, 6);Enqueue(Q, 7);Enqueue(Q, 8);PrintQueue(Q);Dequeue(Q);PrintQueue(Q);Dequeue(Q);PrintQueue(Q);Dequeue(Q);PrintQueue(Q);return (EXIT_SUCCESS);
}

输出截图

输入图片说明

转载于:https://my.oschina.net/stream/blog/692855

http://www.lbrq.cn/news/2396503.html

相关文章:

  • 微信看视频打赏网站建设头条新闻最新消息
  • 医院网站 功能google seo是什么
  • wordpress 图片网站推销产品的软文500字
  • 用模板做网站的方法免费seo培训
  • 做名片制作网站有什么软文发布软件
  • 网站建设修改营销网站建设哪家好
  • 朝阳专业网站建设公司产品销售方案与营销策略
  • 网站建设与规划实验心得百度seo关键词优化电话
  • 深圳建设网站公司全球访问量top100网站
  • 针对人群不同 网站做细分关键词三年级
  • 物联网开发平台新河seo怎么做整站排名
  • 北京政府网站开发外贸网站
  • 古董专家官方网站微信新冠疫情最新消息今天公布
  • 浙江省建设委员会网站aso排名优化知识
  • 朔州市2018年建设工程网站如何在百度上营销
  • 网站解析出问题 邮件收不到了网络营销策划师
  • 武安建设局网站十大引擎网址
  • wordpress https错误推广学院seo教程
  • 找人做博彩网站互动营销平台
  • 哪个网站可以做任务nba最新消息
  • 做风帆网站需要多少钱如何搭建网站平台
  • 网站设计公司网站设计公司今天今日头条新闻
  • 广东贸易网站开发百度seo建议
  • 门户网网站seo怎么做品牌营销的四大策略
  • 合肥网站建设怎么做湖南seo优化报价
  • 网站禁用复制流量神器
  • 无锡 网站 seo 优化网站建设公司业务
  • 商贸网站建设广州网络营销推广
  • 网站内部优化软文推广案例大全
  • 电子商城网站开发武汉seo服务外包
  • QT窗口(7)-QColorDiag
  • RS485转Profibus网关助力涡街液体流量计与300PLC高效通讯
  • math.h函数
  • Node.js链接MySql
  • 光伏财务管理:在阳光与资本的精密计算中前行
  • 25数据库三级备考自整理笔记