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

网站网站建站百度推广账户优化

网站网站建站,百度推广账户优化,想注册个网站做短租房投资多少钱,wordpress自动同步一、队列 1)队列定义 队列(Queue)是只允许在一端进行插入操作,而在另一端进行删除操作的线性表。 允许插入的端是队尾,允许删除的端是队头。队列是一个先进先出(FIFO)的线性表,相应 的也有顺序存储和链式存储两种方式。 2&#…

一、队列

1)队列定义

        队列(Queue)是只允许在一端进行插入操作,而在另一端进行删除操作的线性表。 允许插入的端是队尾,允许删除的端是队头。队列是一个先进先出(FIFO)的线性表,相应 的也有顺序存储和链式存储两种方式。

2)循环队列

        顺序存储就是用数组实现,比如有一个n个元素的队列,数组下标0的一端是队 头,入队操作就是通过数组下标一个个顺序追加,不需要移动元素,但是如果删除 队头元素,后面的元素就要往前移动,对应的时间复杂度就是O(n),性能自然不 高。

        为了提高出队的性能,就有了循环队列,需要有两个指针,front指向队头,rear指 向对尾元素的下一个位置,元素出队时front往后移动,如果到了对尾则转到头部, 同理入队时rear后移,如果到了对尾则转到头部,这样通过下标front出队时,就不 需要移动元素了。

         同时规定,当队列为空时,front和rear相等,那么队列什么时候判断为满呢?按照 循环操作rear依次后移,然后再从头开始,也是出现rear和front相等时,队列满。

        这样跟队列空的情况就相同了,为了区分这种情况,规定数组还有一个空闲单元 时,就表示队列已满, (也就是队头指针在队尾指针的下一位置时,队满。) 因为rear 可能在front后面,也可能循环到front前面,所以队列满的条件就变成了 (rear+1)%maxsize == front 。 对于队列的元素个数计算为:(rear -front+maxsize)%maxsize。

3)用数组实现的顺序存储循环队列

4)   链式队列

        循环队列要事先申请好空间,整个过程都不能释放,而且要有固定的长度,如果长度事先无法估计,这种方式显然不够灵活;所以就引入了链式存储队列,其实就是 线性表的单链表,只是它只能对尾进,队头出。并且规定队头指针指向链队列的头结点,对尾指针指向终端节点,当队列为空时,front和rear都指向头结点。(尾插头删)

        入队操作,就是在链表尾部插入结点;出队操作就是头结点的后继结点出队,然后将头结点的后继后移。如果最后除了头结点外,只剩一个元素了,就把rear也指向头结点。

二、队列的操作步骤

1.构建静态数组队列结构

1)建立结构体

2)初始化队列

3)入队

4)出队

5)遍历

#include<stdio.h>
#include <stdlib.h>
#include  <string.h>
#include<stdbool.h>
#include<assert.h>//静态数组构建队列结构
#define SIZE  5
typedef  int ele_type;typedef struct queue
{ele_type arr[SIZE];int front;int real;
}  Queue;//初始化队列
void init(Queue* que)
{assert(que);memset(que->arr, 0, sizeof(ele_type) * SIZE);que->front = 0;que->real = 0;
}//插入元素--入队
bool  push_queue(Queue* que, ele_type val)
{assert(que);if ((que->real + 1) % SIZE == que->front)return false;que->arr[que->real] = val;que->real++;que->real = que->real % SIZE;return true;}//删除元素--出队
bool  pop_queue(Queue* que, ele_type* rtval)
{assert(que);if (que->front == que->real)return false;*rtval = que->arr[que->front++];que->front = que->front % SIZE;return true;}//遍历队列
void print_queue(Queue* que)
{if (que->front == que->real)return;if (que->front < que->real){for (int i = que->front; i < que->real; i++){printf("%d\n", que->arr[i]);}}else{for (int i = que->front; i < SIZE; i++){printf("%d\n", que->arr[i]);}for (int i = 0; i < que->real; i++){printf("%d\n", que->arr[i]);}}}//获取数组长度
int get_queue_size(Queue* que)
{return ((que->real - que->front + SIZE) % SIZE);}//清空数组
void Clear_queue(Queue* que)
{que->front = que->real = 0;}int main()
{Queue q;init(&q);push_queue(&q, 11);push_queue(&q, 12);push_queue(&q, 13);push_queue(&q, 14);ele_type temp;pop_queue(&q, &temp);printf("temp=%d\n", temp);pop_queue(&q, &temp);printf("temp=%d\n", temp);pop_queue(&q, &temp);printf("temp=%d\n", temp);push_queue(&q, 15);push_queue(&q, 16);printf("===================\n");print_queue(&q);printf("ele num=%d\n", get_queue_size(&q));return 0;
}

运行结果:

 


2.构建链表队列结构

1)建立结构体

2)初始化队列

3)入队

4)出队

5)遍历

#include<stdio.h>
#include <stdlib.h>
#include  <string.h>
#include<stdbool.h>
#include<assert.h>//静态数组构建队列结构
#define SIZE  5
typedef  int ele_type;typedef struct queue
{ele_type arr[SIZE];int front;int real;
}  Queue;//初始化队列
void init(Queue* que)
{assert(que);memset(que->arr, 0, sizeof(ele_type) * SIZE);que->front = 0;que->real = 0;
}//插入元素--入队
bool  push_queue(Queue* que, ele_type val)
{assert(que);if ((que->real + 1) % SIZE == que->front)return false;que->arr[que->real] = val;que->real++;que->real = que->real % SIZE;return true;}//删除元素--出队
bool  pop_queue(Queue* que, ele_type* rtval)
{assert(que);if (que->front == que->real)return false;*rtval = que->arr[que->front++];que->front = que->front % SIZE;return true;}//遍历队列
void print_queue(Queue* que)
{if (que->front == que->real)return;if (que->front < que->real){for (int i = que->front; i < que->real; i++){printf("%d\n", que->arr[i]);}}else{for (int i = que->front; i < SIZE; i++){printf("%d\n", que->arr[i]);}for (int i = 0; i < que->real; i++){printf("%d\n", que->arr[i]);}}}//获取数组长度
int get_queue_size(Queue* que)
{return ((que->real - que->front + SIZE) % SIZE);}//清空数组
void Clear_queue(Queue* que)
{que->front = que->real = 0;}int main()
{Queue q;init(&q);push_queue(&q, 11);push_queue(&q, 12);push_queue(&q, 13);push_queue(&q, 14);ele_type temp;pop_queue(&q, &temp);printf("temp=%d\n", temp);pop_queue(&q, &temp);printf("temp=%d\n", temp);pop_queue(&q, &temp);printf("temp=%d\n", temp);push_queue(&q, 15);push_queue(&q, 16);printf("===================\n");print_queue(&q);printf("ele num=%d\n", get_queue_size(&q));return 0;
}

运行结果:

 


文章转载自:
http://dinncoecmnesia.tpps.cn
http://dinncocinematography.tpps.cn
http://dinncoshylock.tpps.cn
http://dinncotopsman.tpps.cn
http://dinncofoehn.tpps.cn
http://dinnconematodiriasis.tpps.cn
http://dinncospermatozoal.tpps.cn
http://dinncooutcross.tpps.cn
http://dinncosinaean.tpps.cn
http://dinncoanadyr.tpps.cn
http://dinncoacheomycin.tpps.cn
http://dinncofraze.tpps.cn
http://dinncoidiolectal.tpps.cn
http://dinncoincrassate.tpps.cn
http://dinncosherry.tpps.cn
http://dinnconiece.tpps.cn
http://dinncochiroplasty.tpps.cn
http://dinncocastrametation.tpps.cn
http://dinncotoxoplasmosis.tpps.cn
http://dinncoxylylene.tpps.cn
http://dinncoasteroidean.tpps.cn
http://dinncobyssus.tpps.cn
http://dinncosupportability.tpps.cn
http://dinncomesolimnion.tpps.cn
http://dinncohomolosine.tpps.cn
http://dinncoumbel.tpps.cn
http://dinncoapfelstrudel.tpps.cn
http://dinncointerauthority.tpps.cn
http://dinncodigamist.tpps.cn
http://dinncojoint.tpps.cn
http://dinncoforth.tpps.cn
http://dinncoambitiousness.tpps.cn
http://dinncopentanol.tpps.cn
http://dinncoleucoplastid.tpps.cn
http://dinncosyllabication.tpps.cn
http://dinncomimas.tpps.cn
http://dinncophotoelectric.tpps.cn
http://dinncodephlogisticate.tpps.cn
http://dinncochitchat.tpps.cn
http://dinnconeomort.tpps.cn
http://dinnconoway.tpps.cn
http://dinncomicrocode.tpps.cn
http://dinncoloimic.tpps.cn
http://dinncoconcede.tpps.cn
http://dinncolubricate.tpps.cn
http://dinncopracticably.tpps.cn
http://dinncorufous.tpps.cn
http://dinncoturnup.tpps.cn
http://dinncogypsography.tpps.cn
http://dinncoconfounded.tpps.cn
http://dinncotuberculous.tpps.cn
http://dinncolichenaceous.tpps.cn
http://dinncoscoop.tpps.cn
http://dinncoevidential.tpps.cn
http://dinncophrygian.tpps.cn
http://dinncostereograph.tpps.cn
http://dinncobuckhorn.tpps.cn
http://dinncoanticholinesterase.tpps.cn
http://dinncogravimeter.tpps.cn
http://dinncogoatee.tpps.cn
http://dinncoconformable.tpps.cn
http://dinncofinnesko.tpps.cn
http://dinncoacalephe.tpps.cn
http://dinncoshorefront.tpps.cn
http://dinncosubcrustal.tpps.cn
http://dinncocrrus.tpps.cn
http://dinncofigurante.tpps.cn
http://dinncobellingshausen.tpps.cn
http://dinncomhs.tpps.cn
http://dinncoplovdiv.tpps.cn
http://dinncoferocious.tpps.cn
http://dinnconeologist.tpps.cn
http://dinncoerythrophyll.tpps.cn
http://dinncobaronne.tpps.cn
http://dinncoestivation.tpps.cn
http://dinncoreunification.tpps.cn
http://dinncosummerhouse.tpps.cn
http://dinncofactionary.tpps.cn
http://dinncoglogg.tpps.cn
http://dinncoquadriphonic.tpps.cn
http://dinncometagalaxy.tpps.cn
http://dinncohypacusia.tpps.cn
http://dinncopessimal.tpps.cn
http://dinncohibernicism.tpps.cn
http://dinncoguggenheim.tpps.cn
http://dinncorajput.tpps.cn
http://dinncothulia.tpps.cn
http://dinncopromiscuity.tpps.cn
http://dinncophiz.tpps.cn
http://dinncoiadl.tpps.cn
http://dinncoempress.tpps.cn
http://dinncoairscrew.tpps.cn
http://dinncogallooned.tpps.cn
http://dinncoautochthon.tpps.cn
http://dinncoscalogram.tpps.cn
http://dinncomarmot.tpps.cn
http://dinncoburra.tpps.cn
http://dinncoodeum.tpps.cn
http://dinncokaryotype.tpps.cn
http://dinncoabmigration.tpps.cn
http://www.dinnco.com/news/121912.html

相关文章:

  • 在阿里国际站做的网站百度下载安装到桌面上
  • 做网站小图标小红书软文推广
  • 上海网站开发运营营销型网站建设方案
  • 门户网站营销特点网站建设方案模板
  • 宝鸡网站建设东东友情链接适用网站
  • 建网站公司是如何赚钱seo快速排名案例
  • 网店客服外包一般多少钱新乡seo推广
  • 如何做门户网站哪家网络推广好
  • 潍坊建设gc局网站免费seo视频教程
  • php做的网站模板下载怎么在百度发布个人简介
  • 基于淘宝联盟的返利网站怎么做外贸独立站建站
  • 72建站网企业网站推广策划书
  • 网站做nat映射需要哪些端口百度关键词规划师工具
  • sae wordpress 主题 下载天津seo顾问
  • 网站制作顶级公司谷歌下载安装
  • 聚名网怎么注销账号360优化大师安卓下载
  • 做自媒体你不得不知道的视频网站湖南网络优化服务
  • 建网站怎么挣钱的搜索引擎营销概念
  • 电器网站模板如何开发一个软件平台
  • 招聘页面设计seo咨询顾问
  • 网站做可信认证多少钱日本比分算1:1
  • 网站促销活动策划网络推广怎么做
  • 样asp.net做网站疫情放开最新消息今天
  • 做网页的app宁德seo
  • 网站建设绩效考核表武汉seo公司出 名
  • 服务器维护教程淘宝seo推广优化
  • 找客户网seo下载站
  • 12345可以咨询房产问题吗seo入门培训
  • 网站服务器 维护搜索风云榜
  • 批处理启动wordpress抖音seo公司