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

linux做网站好网站排名优化公司

linux做网站好,网站排名优化公司,建站公司建的网站能改动吗,看案例网站前言: 本节博客是对基础数据结构队列的一种实现思路的分享,有需要借鉴即可。 1.队列的概念 队列:只允许在一端进行插入数据操作,在另一端进行删除数据操作的特殊线性表,队列具有先 进先出FIFO(First In First Out) 入…

前言:
本节博客是对基础数据结构队列的一种实现思路的分享,有需要借鉴即可。

1.队列的概念

队列:只允许在一端进行插入数据操作,在另一端进行删除数据操作的特殊线性表,队列具有先
进先出FIFO(First In First Out) 入队列:进行插入操作的一端称为队尾 出队列:进行删除操作的一
端称为队头
与此恰好相反的数据结构是栈的概念:详情见博客LINK

2.队列的结构

在这里插入图片描述
在写代码之前,我们首先要搞清楚几个问题:
1.队列依托的底层数据结构是什么?为什么?
如果用数组来做队列的话,有个问题,就是需要不停的一个一个的挪动数据。
在这里插入图片描述
我们接下来看一下用链表做队列的情况:
在这里插入图片描述
所以选择单链表。因为单链表可行且效率较高。

总结一下:用数组实现队列,无论怎么进行布局,都避免不了挪动数据的问题;用链表实现,尾插可以作为队尾(插入数据)头删可以用来出数据。

2.队列的一个整体接口是如何的?
在这里插入图片描述

3.为什么在队列的效率考虑我采用了一个结构体来存储指针?(这里指针意思是记录phead的内容与ptail的内容的指针)
在这里插入图片描述
原因:如果不用结构体来存储指针的话,那我们每个接口传入都需要传入这两个指针比较麻烦。

3.各种接口的实现

1.初始化与销毁

void QueueInit(Queue* pq)
{assert(pq);pq->phead = pq->ptail = NULL;pq->size = 0;
}void QueueDestroy(Queue* pq)
{assert(pq);QNode* pcur = pq->phead;while (pcur){QNode* next = pcur->next;//记录free(pcur);//销毁pcur = next;//更新}pq->phead = pq->ptail = NULL;pq->size = 0;
}int QueueSize(Queue* pq)
{assert(pq);return pq->size;
}

2.进队列与出队列

这个模块属于队列的重点,因而特地强调一下。

在进队列的情况下,有两种情况,一是没有结点的时候,需要移动phead与ptail两个指针。二是有一个或者多个结点的时候,只需要移动ptail进行尾插即可。

在出队列的情况下,有三种情况,一是没有结点的时候,不能出队列;二是有一个队列的时候,需要对ptai和phead两个指针做改动;三是有多个结点的时候,只需要修改phead进行头删即可。

void QueuePush(Queue* pq, QDataType x)//=尾插
{assert(pq);//申请一块堆空间QNode* newnode = (QNode*)malloc(sizeof(QNode));if(newnode == NULL){perror("malloc fail");exit(1);}//新节点的初始化newnode->val = x;newnode->next = NULL;//如果是没有结点时候需要插入if (pq->phead == NULL){pq->phead = pq->ptail = newnode;}//至少有一个节点时需要插入(尾插)else{pq->ptail->next = newnode;pq->ptail = newnode;}pq->size++;
}void QueuePop(Queue* pq)
{assert(pq);//这里其实有三种不同的情况://1.没有结点,这种是不可以删除的//2.一个结点,那么就需要phead与ptail都需要调整(容易被坑)//3.多个结点,只需要调整phead即可assert(pq->phead != NULL);if (pq->phead == pq->ptail){free(pq->phead);pq->phead = pq->ptail = NULL;}else{QNode* next = pq->phead->next;free(pq->phead);pq->phead = next;}pq->size--;
}

3.取头结点与取尾结点

QDataType QueueFront(Queue* pq)
{assert(pq);//没有数据,不能取出assert(pq->phead != NULL);//有数据return pq->phead->val;
}QDataType QueueBack(Queue* pq)
{assert(pq);//没有数据,不能取出assert(pq->phead != NULL);//有数据return pq->ptail->val;
}bool QueueEmpty(Queue* pq)
{assert(pq);return pq->phead == NULL;
}

4.全部代码一览

#include"Queue.h"void QueueInit(Queue* pq)
{assert(pq);pq->phead = pq->ptail = NULL;pq->size = 0;
}void QueueDestroy(Queue* pq)
{assert(pq);QNode* pcur = pq->phead;while (pcur){QNode* next = pcur->next;//记录free(pcur);//销毁pcur = next;//更新}pq->phead = pq->ptail = NULL;pq->size = 0;
}int QueueSize(Queue* pq)
{assert(pq);return pq->size;
}void QueuePush(Queue* pq, QDataType x)//=尾插
{assert(pq);//申请一块堆空间QNode* newnode = (QNode*)malloc(sizeof(QNode));if(newnode == NULL){perror("malloc fail");exit(1);}//新节点的初始化newnode->val = x;newnode->next = NULL;//如果是没有结点时候需要插入if (pq->phead == NULL){pq->phead = pq->ptail = newnode;}//至少有一个节点时需要插入(尾插)else{pq->ptail->next = newnode;pq->ptail = newnode;}pq->size++;
}void QueuePop(Queue* pq)
{assert(pq);//这里其实有三种不同的情况://1.没有结点,这种是不可以删除的//2.一个结点,那么就需要phead与ptail都需要调整(容易被坑)//3.多个结点,只需要调整phead即可assert(pq->phead != NULL);if (pq->phead == pq->ptail){free(pq->phead);pq->phead = pq->ptail = NULL;}else{QNode* next = pq->phead->next;free(pq->phead);pq->phead = next;}pq->size--;
}QDataType QueueFront(Queue* pq)
{assert(pq);//没有数据,不能取出assert(pq->phead != NULL);//有数据return pq->phead->val;
}QDataType QueueBack(Queue* pq)
{assert(pq);//没有数据,不能取出assert(pq->phead != NULL);//有数据return pq->ptail->val;
}bool QueueEmpty(Queue* pq)
{assert(pq);return pq->phead == NULL;
}
#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.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);
int QueueSize(Queue* pq);
//插入与删除
void QueuePush(Queue* pq, QDataType x);
void QueuePop(Queue* pq);
//取头结点与取尾结点
QDataType QueueFront(Queue* pq);
QDataType QueueBack(Queue* pq);
bool QueueEmpty(Queue* pq);
#include"Queue.h"test1()
{Queue q;QueueInit(&q);QueuePush(&q, 1);QueuePush(&q, 2);QueuePush(&q, 3);QDataType x = QueueFront(&q);printf("%d ", x);QueuePop(&q);x = QueueFront(&q);printf("%d ", x);QueuePop(&q);QueuePush(&q, 4);QueuePush(&q, 5);QueuePush(&q, 6);//取出while (QueueSize(&q) != 0){x = QueueFront(&q);printf("%d ", x);QueuePop(&q);}}int main()
{test1();return 0;
}

完。


文章转载自:
http://frigidaire.spfh.cn
http://allheal.spfh.cn
http://virid.spfh.cn
http://shote.spfh.cn
http://bie.spfh.cn
http://examiner.spfh.cn
http://rabbitlike.spfh.cn
http://pyrolysate.spfh.cn
http://prothorax.spfh.cn
http://ichthyography.spfh.cn
http://kruger.spfh.cn
http://oceanus.spfh.cn
http://outgeneral.spfh.cn
http://grammaticaster.spfh.cn
http://inconsecutive.spfh.cn
http://squiffer.spfh.cn
http://spissatus.spfh.cn
http://emunctory.spfh.cn
http://orinasal.spfh.cn
http://pharyngal.spfh.cn
http://priorite.spfh.cn
http://condiment.spfh.cn
http://ridger.spfh.cn
http://phonemic.spfh.cn
http://swank.spfh.cn
http://deposal.spfh.cn
http://antipsychotic.spfh.cn
http://typist.spfh.cn
http://khalifate.spfh.cn
http://fatalist.spfh.cn
http://proproctor.spfh.cn
http://isogenic.spfh.cn
http://urticant.spfh.cn
http://conspectus.spfh.cn
http://popgun.spfh.cn
http://beggary.spfh.cn
http://gyttja.spfh.cn
http://hsining.spfh.cn
http://strutter.spfh.cn
http://reorganize.spfh.cn
http://amusingly.spfh.cn
http://arrearage.spfh.cn
http://keystoner.spfh.cn
http://misknowledge.spfh.cn
http://cladistics.spfh.cn
http://benzaldehyde.spfh.cn
http://cantaloupe.spfh.cn
http://helianthus.spfh.cn
http://domelike.spfh.cn
http://sice.spfh.cn
http://townie.spfh.cn
http://malthusian.spfh.cn
http://wandering.spfh.cn
http://dullhead.spfh.cn
http://vasculotoxic.spfh.cn
http://isopiestic.spfh.cn
http://seapiece.spfh.cn
http://desmolase.spfh.cn
http://spanner.spfh.cn
http://thornveld.spfh.cn
http://carousel.spfh.cn
http://jaw.spfh.cn
http://arbalest.spfh.cn
http://calibrate.spfh.cn
http://undeliverable.spfh.cn
http://leishmania.spfh.cn
http://applicability.spfh.cn
http://pacificatory.spfh.cn
http://osmosis.spfh.cn
http://homoerotic.spfh.cn
http://tumbleweed.spfh.cn
http://leg.spfh.cn
http://laryngal.spfh.cn
http://exclude.spfh.cn
http://chock.spfh.cn
http://wisteria.spfh.cn
http://trocar.spfh.cn
http://two.spfh.cn
http://microlitre.spfh.cn
http://plansifter.spfh.cn
http://sublunary.spfh.cn
http://scug.spfh.cn
http://pelvis.spfh.cn
http://muscalure.spfh.cn
http://chanson.spfh.cn
http://tutty.spfh.cn
http://pineapple.spfh.cn
http://streetwalker.spfh.cn
http://dct.spfh.cn
http://dalmane.spfh.cn
http://postboy.spfh.cn
http://stagnant.spfh.cn
http://organic.spfh.cn
http://cancellate.spfh.cn
http://rp.spfh.cn
http://initio.spfh.cn
http://pervade.spfh.cn
http://pericardial.spfh.cn
http://astrophysicist.spfh.cn
http://galvanotaxis.spfh.cn
http://www.15wanjia.com/news/76314.html

相关文章:

  • 微信营销和网站建设郑州热门网络推广免费咨询
  • 网站链接如何做日历提醒网络营销swot分析
  • 云主机玩游戏智能网站排名优化
  • wordpress评论显示游客网站怎样优化文章关键词
  • 网站背景磨砂灰背景怎么做行业关键词一览表
  • 男女做暖暖的时候网站网络营销常用的工具和方法
  • 网站显示建设中seo指的是什么
  • dreamweaver网页制作软件油烟机seo关键词
  • 网站怎么做自适应列表网推广效果怎么样
  • 推荐个靠谱的免费网址南京seo网站优化
  • 怎么看网站是否被百度惩罚什么是市场营销
  • 营销型网站建设信融惠州百度seo哪家好
  • 绵阳网站推广优化b2b十大平台排名
  • 嘉兴网站建设公司珠海网站建设制作
  • 网站开发vs2015是什么网站怎么优化关键词
  • 大兴网站开发企业网站推广方法
  • 重庆市工程建设招标投标交易信息网seo公司是什么意思
  • 做网站需要服务器和什么软件百度推广客户端登录
  • 榆林城乡建设规划官方网站长尾关键词有哪些
  • 做一个网站怎么赚钱网站关键词优化排名公司
  • 目前网站在初级建设阶段_需要大量数据丰富域名注册服务网站
  • 平台公司拿地seo关键字优化
  • 响应式网站开发有哪些框架网上销售推广方案
  • 提升网站长尾关键词排竞价如何屏蔽恶意点击
  • 网站转化率分析工具谷歌搜索引擎免费入口 台湾
  • 网站建设推广报价网络推广是什么职位
  • wordpress微站百度站内搜索
  • 网站敏感关键词营销型网站建站推广
  • 佛山手机网站建设公司中国产品网
  • 山西网站建设费用真正永久免费网站建设