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

佛山做网站-准度科技公司昆明百度推广优化

佛山做网站-准度科技公司,昆明百度推广优化,网络营销与策划书,快速建设房产网站数据结构——队列的实现(单链表) 一.队列1.1队列的概念及结构 二.队列的实现2.1 头文件的实现——(Queue.h)2.2 源文件的实现—— (Queue.c)2.3 源文件的实现—— (test.c) 三.队列的…

数据结构——队列的实现(单链表)

  • 一.队列
    • 1.1队列的概念及结构
  • 二.队列的实现
    • 2.1 头文件的实现——(Queue.h)
    • 2.2 源文件的实现—— (Queue.c)
    • 2.3 源文件的实现—— (test.c)
  • 三.队列的实际数据测试展示
    • 3.1正常出队列入队列
    • 3.2 入队列的同时存在出队列

一.队列

1.1队列的概念及结构

在这里插入图片描述

二.队列的实现

2.1 头文件的实现——(Queue.h)

Queue.h
#pragma once#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<assert.h>typedef int QDataType;
typedef struct QueueNode
{QDataType val;struct QueueNode* next;
}QNode;typedef struct Queue
{QNode* phead;QNode* ptail;int size;
}Queue;//初始化/销毁
void QueueInit(Queue* pq);
void QueueDestroy(Queue* pq);//出队/入队
void QueuePush(Queue* pq, QDataType x);
void QueuePop(Queue* pq);
//获取队头元素/队尾元素
QDataType QueueFront(Queue* pq);
QDataType QueueBack(Queue* pq);
//判空/统计队列元素个数
bool QueueEmpty(Queue* pq);
int QueueSize(Queue* pq);

2.2 源文件的实现—— (Queue.c)

Queue.c
#include"Queue.h"//初始化/销毁
void QueueInit(Queue* pq)
{assert(pq);pq->phead = pq->ptail = NULL;pq->size = 0;
}
void QueueDestroy(Queue* pq)
{assert(pq);QNode* cur = pq->phead;while (cur){QNode* Next = cur->next;free(cur);cur = Next;}pq->phead = pq->ptail = NULL;pq->size = 0;
}//队尾入队/队首出队
void QueuePush(Queue* pq, QDataType x)
{assert(pq);QNode* Newnode = (QNode*)malloc(sizeof(QNode));if (Newnode == NULL){perror("malloc fail");return;}Newnode->val = x;Newnode->next = NULL;if (pq->phead == NULL){pq->phead = pq->ptail = Newnode;}else{pq->ptail->next = Newnode;pq->ptail = pq->ptail->next;}pq->size++;
}
void QueuePop(Queue* pq)
{assert(pq);assert(pq->phead);QNode* del = pq->phead;pq->phead = pq->phead->next;free(del);del = NULL;if (pq->phead == NULL)pq->ptail = NULL;pq->size--;}//获取队头元素/队尾元素
QDataType QueueFront(Queue* pq)
{assert(pq);assert(pq->phead);return pq->phead->val;
}
QDataType QueueBack(Queue* pq)
{assert(pq);assert(pq->ptail);return pq->ptail->val;}
//判空/统计队列元素个数
bool QueueEmpty(Queue* pq)
{assert(pq);return pq->phead == NULL;
}
int QueueSize(Queue* pq)
{assert(pq);return pq->size;
}

2.3 源文件的实现—— (test.c)

test.c
#include"Queue.h"int main()
{Queue S;QueueInit(&S);QueuePush(&S, 1);QueuePush(&S, 2);printf("%d ", QueueFront(&S));QueuePop(&S);QueuePush(&S, 3);QueuePush(&S, 4);printf("%d ", QueueFront(&S));QueuePop(&S);QueuePush(&S, 5);while (!QueueEmpty(&S)){printf("%d ", QueueFront(&S));QueuePop(&S);}QueueDestroy(&S);
}

三.队列的实际数据测试展示

1.出入队列的方式:队尾进入,对首出队列。
2.出队列和入队列的关系是:一对一的。

3.1正常出队列入队列

在这里插入图片描述

3.2 入队列的同时存在出队列

在这里插入图片描述

http://www.dinnco.com/news/9332.html

相关文章:

  • 网站链接怎么做标记建站平台有哪些
  • mac os 做网站热搜词排行榜
  • 国内外html5网站建设状况站长工具源码
  • 网站 什么语言开发的橘子seo查询
  • 网站建设脱颖而出企业文化设计
  • 网站定制的公司哪家好网站推广方案范例
  • 个人网站推广湖南靠谱的关键词优化
  • 免费网站建设平台宁波seo推荐推广平台
  • 深圳网页设计兴田德润实惠菏泽资深seo报价
  • 百姓网站制作网站推广优化服务
  • 线下推广是做什么的网站推广优化怎样
  • 无限动力营销型网站建设免费seo公司
  • 企业网站用vps还是虚拟主机百家号关键词排名
  • 质量基础设施一站式服务工作站宁波seo外包服务
  • 佛山市做网站的公司青岛网站建设运营推广
  • 有动效网站营销策划案
  • 深圳CSS3网站建设价格橙子建站
  • 重庆建站管理系统信息知识付费网站搭建
  • 用dedecms织梦做中英文网站郴州网站建设推广公司
  • 关键词自动优化工具qq群排名优化软件购买
  • 喀什网站建设营销渠道方案
  • 网站开发网络课程营销型网站有哪些功能
  • 广州荔湾做网站公司站长工具seo综合查询分析
  • 深圳积分商城网站制作高级搜索引擎
  • 建站之星官网建设刷关键词排名seo软件
  • 网站建设的基本流程如何做网络推广运营
  • 泊头做网站的全球疫情最新数据消息
  • 仪征市建设局网站网站的优化从哪里进行
  • 不要域名做网站站长之家源码
  • 淘宝代码网站有哪些小程序开发需要哪些技术