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

自己做家具网站网页设计综合案例

自己做家具网站,网页设计综合案例,wordpress 微网站,一个网站可以做多少地区词目录 1.队列 1.1队列的概念及结构 1.2 队列的实际应用联想 1.3队列的实现 2. 队列应用——队列实现栈 主要思路 1.队列 1.1队列的概念及结构 队列:只允许在一端进行插入数据操作,在另一端进行删除数据操作的特殊线性表,队列具有先进…

目录

1.队列

1.1队列的概念及结构

1.2 队列的实际应用联想

1.3队列的实现

2. 队列应用——队列实现栈

主要思路


1.队列

1.1队列的概念及结构

队列:只允许在一端进行插入数据操作,在另一端进行删除数据操作的特殊线性表,队列具有先进先出FIFO(First In First Out) 入队列:进行插入操作的一端称为 队尾 出队列:进行删除操作的一端称为 队头

1.2 队列的实际应用联想

1. 基于队列的特点--先进先出,可以联想到大厅服务中的叫号机先到的先拿号,先拿号的先办业务,队列中的人是在等的人,办完业务为出队列,取号为如队列。

2. 也可以是查找和自己间接相关的人,像是查找qq好友的好友,开始自己在队列中,后来将自己出队列,将自己好友入队列,再将队列中的人出来,他们的好友再入队列,当然入队列的时候肯定有限制,不能是和之前重复的,以此类推,即可知道和自己外围相关的人,

注(仅为有代码新人的有端联想,不一定真正适合这些情况)

1.3队列的实现

队列也可以数组和链表的结构实现,使用链表的结构实现更优一些,因为如果使用数组的结构,出队列在数组头上出数据,效率会比较低。
下面我们来实现队列:
分两个文件:Queue.h与Queue.c
Queue.h进行头文件和函数的声明,以及队列结构的创建
#pragma once
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>//方便后面对不同数据的操作
typedef int QDataType;//链式队列-队列结点结构体
typedef struct QListNode
{QDataType _data;struct	QListNode* _pnext;
}QNode;//队列结构体
typedef struct Queue
{QNode* _phead;QNode* _ptail;int _size;
}Queue;// 初始化队列
void QueueInit(Queue* q);
// 队尾入队列
void QueuePush(Queue* q, QDataType data);
// 队头出队列
void QueuePop(Queue* q);
// 获取队列头部元素
QDataType QueueFront(Queue* q);
// 获取队列队尾元素
QDataType QueueBack(Queue* q);
// 获取队列中有效元素个数
int QueueSize(Queue* q);
// 检测队列是否为空,如果为空返回非零结果,如果非空返回0 
bool QueueEmpty(Queue* q);
// 销毁队列
void QueueDestroy(Queue* q);

Queue.c进行队列相关函数的实现

#include "Queue.h"//队列初始化
void QueueInit(Queue* pst)
{assert(pst);pst->_phead = pst->_ptail = NULL;pst->_size = 0;
}// 队尾入队列
void QueuePush(Queue* pst,QDataType x)
{assert(pst);QNode* newnode = (QNode*)malloc(sizeof(QNode));newnode->_data = x;newnode->_pnext = NULL;if (pst->_phead == NULL){pst->_phead = pst->_ptail = newnode;}else{pst->_ptail->_pnext = newnode;pst->_ptail = newnode;}pst->_size++;
}// 队头出队列
void QueuePop(Queue* pst)
{assert(pst);assert(pst->_size);QNode* next = pst->_phead->_pnext;free(pst->_phead);pst->_phead = next;pst->_size--;
}// 获取队列队尾元素
QDataType QueueBack(Queue* pst)
{assert(pst);assert(pst->_size);return pst->_ptail->_data;
}// 获取队列头部元素
QDataType QueueFront(Queue* pst)
{assert(pst);assert(pst->_size);return pst->_phead->_data;
}// 获取队列中有效元素个数
int QueueSize(Queue* pst)
{assert(pst);return pst->_size;
}// 检测队列是否为空,如果为空返回True,如果非空返回False 
bool QueueEmpty(Queue* pst)
{assert(pst);return pst->_size == 0;
}// 销毁队列
void QueueDestroy(Queue* pst)
{assert(pst);QNode* cur = pst->_phead;while (cur){QNode* next = cur->_pnext;free(cur);cur = next;}pst->_size = 0;pst->_phead = pst->_ptail = NULL;
}

2. 队列应用——队列实现栈

225. 用队列实现栈 - 力扣(LeetCode)

题目:

我们用直接使用前队列的代码实现栈。

主要思路

创建两个队列相互导数据实现后进先出的效果,;压数据时直接在有数据的那个队列中插入数据,出栈时将有数据的队列中的size-1个数据导入另一个队列里,则第一个队列中剩下的那个数据是我们要出栈的数据,这就是主要思路。

下面是代码演示:(代码有点长但是前面的大部分都是前面实现队列的代码,直接复制粘贴的)

typedef int QDataType;
// 链式队列-队列结点结构体
typedef struct QListNode {QDataType _data;struct QListNode* _pnext;
} QNode;// 队列结构体
typedef struct Queue {QNode* _phead;QNode* _ptail;int _size;
} Queue;// 队列初始化
void QueueInit(Queue* pst) {assert(pst);pst->_phead = pst->_ptail = NULL;pst->_size = 0;
}// 队尾入队列
void QueuePush(Queue* pst, QDataType x) {assert(pst);QNode* newnode = (QNode*)malloc(sizeof(QNode));newnode->_data = x;newnode->_pnext = NULL;if (pst->_phead == NULL) {pst->_phead = pst->_ptail = newnode;} else {pst->_ptail->_pnext = newnode;pst->_ptail = newnode;}pst->_size++;
}// 队头出队列
void QueuePop(Queue* pst) {assert(pst);assert(pst->_size);QNode* next = pst->_phead->_pnext;free(pst->_phead);pst->_phead = next;pst->_size--;
}// 获取队列队尾元素
QDataType QueueBack(Queue* pst) {assert(pst);assert(pst->_size);return pst->_ptail->_data;
}// 获取队列头部元素
QDataType QueueFront(Queue* pst) {assert(pst);assert(pst->_size);return pst->_phead->_data;
}// 获取队列中有效元素个数
int QueueSize(Queue* pst) {assert(pst);return pst->_size;
}// 检测队列是否为空,如果为空返回True,如果非空返回False
bool QueueEmpty(Queue* pst) {assert(pst);return pst->_size == 0;
}// 销毁队列
void QueueDestroy(Queue* pst) {assert(pst);QNode* cur = pst->_phead;while (cur) {QNode* next = cur->_pnext;free(cur);cur = next;}pst->_size = 0;pst->_phead = pst->_ptail = NULL;
}typedef struct {Queue p1;Queue p2;
} MyStack;MyStack* myStackCreate() {MyStack* st = (MyStack*)malloc(sizeof(MyStack));QueueInit(&(st->p1));QueueInit(&(st->p2));return st;
}void myStackPush(MyStack* obj, int x) {if (!QueueEmpty(&(obj->p1))) {QueuePush(&(obj->p1), x);} else {QueuePush(&(obj->p2), x);}
}int myStackPop(MyStack* obj) {Queue* empty = &(obj->p1);Queue* nonempty = &(obj->p2);if (!QueueEmpty(empty)) {empty = &(obj->p2);nonempty = &(obj->p1);}while (QueueSize(nonempty) > 1) {QueuePush(empty, QueueFront(nonempty));QueuePop(nonempty);}int ret = QueueFront(nonempty);QueuePop(nonempty);return ret;
}int myStackTop(MyStack* obj) {if (!QueueEmpty(&obj->p1)) {return QueueBack(&(obj->p1));} else {return QueueBack(&(obj->p2));}
}
bool myStackEmpty(MyStack* obj) {return QueueEmpty(&(obj->p1)) && QueueEmpty(&(obj->p2));
}void myStackFree(MyStack* obj) {QueueDestroy(&(obj->p1));QueueDestroy(&(obj->p2));free(obj);
}

各位看官姥爷点个赞再走吧,欢迎在评论区讨论。

http://www.yayakq.cn/news/191242/

相关文章:

  • 百科网站开发便捷网站建设推荐
  • 静态网站建设规划dede免费手机网站模板
  • 房地产手机端网站建设怎么在虚拟主机安装wordpress
  • phpcms 生成网站地图专业网站制作定制
  • 西安网站建设公司有哪些成品app直播源码有什么用
  • 南宁做网站比较好的公司有哪些马鞍山的网站建设公司
  • 网站开发付款方式和比例沈阳百度推广排名优化
  • 网站建设环境vs2017js网站开发方法
  • 网站项目运营方案徐州便民信息网
  • 上那个网站找手工活做wordpress地址改不了
  • 企业建站的费用做外贸需要用什么网站
  • 佛山新网站制作营销推广案例
  • 宜昌最权威网站建设公司百度seo培训要多少钱
  • 网站建设的前期工作基础asp。net网站开发
  • 网站建设外包价格网站域名做链接怎么做
  • 网站建设开发计划书东营公共资源交易网
  • 白山商城网站建设青岛网站制作公司排名
  • 简单大气食品农业网站源码很长的网站域名怎么做短
  • 互动科技网站建设网站信息发布制度建设
  • 企业网站建设搭建注册公司有哪些风险
  • 烟台网站建设兼职最简单制作网页
  • 沈阳网站建设开发维护换模板搭建网站怎么做
  • 城乡和住房建设部网站网络营销渠道的设计方案
  • 萝岗网站开发科技公司主要是做什么的
  • 电子商务网站建设实践报告zencart外贸网站建设
  • 足球比赛直播免费观看关键词优化课程
  • 网页制作培训证重要吗南京seo排名扣费
  • 做软件的人叫什么seo优化团队
  • ftp网站模板高端网站制作哪家专业
  • wap网站域名申请主机屋网站搭建设置