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

做网站学什么seo快速排名优化公司

做网站学什么,seo快速排名优化公司,网站设计制作太原,做网站app公司前景用队列实现栈 思路 栈的特点:后进先出 队列的特点:先进先出 使用两个队列实现栈: 我们可以使用两个队列,一个队列为:空队列,一个队列为:非空队列 当我们要出队列时: 将 size - …

用队列实现栈 

思路

栈的特点:后进先出   

队列的特点:先进先出

 使用两个队列实现栈:

 

我们可以使用两个队列,一个队列为:空队列,一个队列为:非空队列

当我们要出队列时:

将 size - 1个数据移动到空队列中,再将最后一个数据出队列,如此往复就可以完成4 3 2 1的出队列顺序

代码(c语言): 

队列的各种功能:

typedef int QDataType;
// 链式结构:表示队列 
typedef struct QListNode
{struct QListNode* _next;QDataType _data;
}QNode;// 队列的结构 
typedef struct Queue
{QNode* _front;QNode* _rear;int size;
}Queue;
// 初始化队列 
void QueueInit(Queue* q) {assert(q);q->size = 0;q->_front = NULL;q->_rear = NULL;
}
// 队尾入队列 
void QueuePush(Queue* q, QDataType data) {assert(q);QNode* newnode = (QNode*)malloc(sizeof(QNode));if (newnode == NULL){perror("QueuePush()::malloc()");return;}newnode->_data = data;newnode->_next = NULL;//队列为NULLif (q->_front == NULL){q->_front = q->_rear = newnode;}else{q->_rear->_next = newnode;q->_rear = q->_rear->_next;}q->size++;
}
// 队头出队列 
void QueuePop(Queue* q) {assert(q);assert(q->size != 0);//单个节点if (q->_front == q->_rear){free(q->_front);q->_front = q->_rear = NULL;}//多个节点else{QNode* next = q->_front->_next;free(q->_front);q->_front = next;}q->size--;
}
// 获取队列头部元素 
QDataType QueueFront(Queue* q) {assert(q);assert(q->_front);//队头不能为NULLreturn q->_front->_data;
}
// 获取队列队尾元素 
QDataType QueueBack(Queue* q) {assert(q);assert(q->_rear);//队尾不能为NULLreturn q->_rear->_data;
}
// 获取队列中有效元素个数 
int QueueSize(Queue* q) {return q->size;
}
// 检测队列是否为空,如果为空返回非零结果,如果非空返回0 
int QueueEmpty(Queue* q) {assert(q);return q->size == 0;
}
// 销毁队列 
void QueueDestroy(Queue* q) {assert(q);QNode* cur = q->_front;while (cur){QNode* next = cur->_next;free(cur);cur = next;}q->_front = q->_rear = NULL;q->size = 0;}

具体实现:

//使用两个队列实现栈
typedef struct {Queue q1;Queue q2;} MyStack;//初始化栈
MyStack* myStackCreate() {//创建一个栈MyStack* newStk = (MyStack*)malloc(sizeof(MyStack));//初始化栈(即初始化两个队列)QueueInit(&(newStk->q1));QueueInit(&(newStk->q2));return newStk;
}//入栈
void myStackPush(MyStack* obj, int x) {//假设法找不为NULL的队列Queue* noempty = &obj->q1;if(QueueSize(noempty) == 0){noempty = &obj->q2;}//往不为NULL队列中插入QueuePush(noempty,x);
}//出栈
int myStackPop(MyStack* obj) {//假设法判断NULL队列,非NULL队列Queue* empty = &obj->q1;Queue* noempty = &obj->q2;if(QueueSize(noempty) == 0){noempty = &obj->q1;empty = &obj->q2;}//将size - 1个数据移动到NULL队列中while(QueueSize(noempty) > 1){QueuePush(empty,QueueFront(noempty));QueuePop(noempty);}//出栈int pop = QueueBack(noempty);QueuePop(noempty);return pop;}//获取栈顶元素
int myStackTop(MyStack* obj) {Queue* noempty = &obj->q1;if(QueueSize(noempty) == 0){noempty = &obj->q2;}//获取栈顶数据,也就是队尾的数据return QueueBack(noempty);}//判NULL
bool myStackEmpty(MyStack* obj) {return QueueEmpty(&obj->q1) && QueueEmpty(&obj->q2);}//销毁栈
void myStackFree(MyStack* obj) {QueueDestroy(&obj->q1);QueueDestroy(&obj->q2);free(obj);}

用栈实现队列

思路

使用两个栈实现队列

固定两个栈,1. 存数据栈(pushst) 2. 出数据栈(popst)

当我们要出数据时,把存数据栈(pushst)导入到 出数据栈(popst)中,在对栈顶取数据,如此往复就可以实现 4 3 2 1 的出栈顺序

代码(c语言):

栈的各种功能:

typedef int STDataType;typedef struct Stack
{STDataType* a;int top;int capacity;
}ST;// 初始化和销毁
void STInit(ST* pst)
{assert(pst);pst->a = NULL;// top指向栈顶数据的下一个位置pst->top = 0;// top指向栈顶数据//pst->top = -1;pst->capacity = 0;
}void STDestroy(ST* pst)
{assert(pst);free(pst->a);pst->a = NULL;pst->top = pst->capacity = 0;
}// 入栈  出栈
void STPush(ST* pst, STDataType x)
{assert(pst);// 扩容if (pst->top == pst->capacity){int newcapacity = pst->capacity == 0 ? 4 : pst->capacity * 2;STDataType* tmp = (STDataType*)realloc(pst->a, newcapacity * sizeof(STDataType));if (tmp == NULL){perror("realloc fail");return;}pst->a = tmp;pst->capacity = newcapacity;}pst->a[pst->top] = x;pst->top++;
}void STPop(ST* pst)
{assert(pst);assert(pst->top > 0);pst->top--;
}// 取栈顶数据
STDataType STTop(ST* pst)
{assert(pst);assert(pst->top > 0);return pst->a[pst->top - 1];
}// 判空
bool STEmpty(ST* pst)
{assert(pst);return pst->top == 0;
}// 获取数据个数
int STSize(ST* pst)
{assert(pst);return pst->top;
}
typedef struct {ST pushst;//用来存储数据ST popst;//用来导出数据} MyQueue;

具体实现

//用两个栈实现队列
MyQueue* myQueueCreate() {MyQueue* new = (MyQueue*)malloc(sizeof(MyQueue));STInit(&new->pushst);STInit(&new->popst);return new;
}//入队列
void myQueuePush(MyQueue* obj, int x) {STPush(&obj->pushst,x);//插入至数据栈(pushst)中}//查看队头元素
int myQueuePeek(MyQueue* obj) {//查看出数据栈(popst),中是否有数据,有则直接查看栈顶数据,没有就把存数据栈(pushst)导入到 出数据栈(popst)中if(STEmpty(&obj->popst)){//把pushst数据全部导入popstwhile(!STEmpty(&obj->pushst)){STPush(&obj->popst,STTop(&obj->pushst));STPop(&obj->pushst);}}//返回出数据栈(popst)栈顶数据return STTop(&obj->popst);}//出队列
int myQueuePop(MyQueue* obj) {//它会帮我们导数据到popst中,popst栈顶的数据就是我们要删除的数据int pop = myQueuePeek(obj);STPop(&obj->popst);return pop;
}//判空
bool myQueueEmpty(MyQueue* obj) {return STEmpty(&obj->pushst) && STEmpty(&obj->popst);//两个栈为NULL则队列为NULL}//销毁队列
void myQueueFree(MyQueue* obj) {STDestroy(&obj->pushst);STDestroy(&obj->popst);free(obj);
}

设计循环队列

        

 思路

利用数组来创建循环队列

代码:

typedef struct {int* a;int head;int rear;//指向最后一个数据的下一个空间int k;
} MyCircularQueue;//初始化循环队列
MyCircularQueue* myCircularQueueCreate(int k) {MyCircularQueue* new = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));//多开一个空间,用来解决数据为满与空的矛盾问题,当然也可以在结构体多加个size解决new->a = (int*)malloc(sizeof(int) * (k + 1));new->head = 0;new->rear = 0;//尾数据的下一个位置new->k = k;return new;
}//插入队列
bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {//判断循环队列满没有,满则不能继续插入if((obj->rear + 1) % (obj->k + 1) == obj->head)//当尾数据指针 + 1 = 头指针时,队列满return false;obj->a[obj->rear] = value;obj->rear++;obj->rear %= obj->k + 1;//循环return true;
}bool myCircularQueueDeQueue(MyCircularQueue* obj) {//判断队列是否为空,为空则不能继续删除if(obj->head == obj->rear)//当尾指针 = 头指针时,队列为空return false;obj->head++;obj->head %= obj->k + 1; //循环return true;
}//返回队列头数据
int myCircularQueueFront(MyCircularQueue* obj) {if(obj->head == obj->rear)return -1;return obj->a[obj->head];
}//返回队列尾数据,即找尾指针指向的上一个地方
int myCircularQueueRear(MyCircularQueue* obj) {if(obj->head == obj->rear)return -1;return obj->a[(obj->k + obj->rear) % (obj->k + 1)];//往前绕k-1去找rear之前的一个数据}//判空
bool myCircularQueueIsEmpty(MyCircularQueue* obj) {//空return obj->head == obj->rear;
}//判满
bool myCircularQueueIsFull(MyCircularQueue* obj) {return (obj->rear + 1) % (obj->k + 1) == obj->head;}//销毁队列
void myCircularQueueFree(MyCircularQueue* obj) {free(obj->a);free(obj);
}


文章转载自:
http://asp.zekgq.cn
http://adherence.zekgq.cn
http://belshazzar.zekgq.cn
http://cancellous.zekgq.cn
http://allopolyploidy.zekgq.cn
http://bevy.zekgq.cn
http://aril.zekgq.cn
http://anaglyph.zekgq.cn
http://bugologist.zekgq.cn
http://chemotactic.zekgq.cn
http://aidance.zekgq.cn
http://betweenness.zekgq.cn
http://aiff.zekgq.cn
http://answer.zekgq.cn
http://abide.zekgq.cn
http://bellyworm.zekgq.cn
http://batcher.zekgq.cn
http://bojardo.zekgq.cn
http://animosity.zekgq.cn
http://brighish.zekgq.cn
http://chroma.zekgq.cn
http://bandobast.zekgq.cn
http://burnous.zekgq.cn
http://byzantinist.zekgq.cn
http://backwoods.zekgq.cn
http://altricial.zekgq.cn
http://caicos.zekgq.cn
http://avgas.zekgq.cn
http://bellwether.zekgq.cn
http://armenoid.zekgq.cn
http://barricade.zekgq.cn
http://centered.zekgq.cn
http://blagoveshchensk.zekgq.cn
http://caldron.zekgq.cn
http://anatomize.zekgq.cn
http://bepuzzle.zekgq.cn
http://birdie.zekgq.cn
http://bottommost.zekgq.cn
http://attenuator.zekgq.cn
http://catastrophism.zekgq.cn
http://biquinary.zekgq.cn
http://celestialize.zekgq.cn
http://amyloidosis.zekgq.cn
http://apparente.zekgq.cn
http://barber.zekgq.cn
http://aerogramme.zekgq.cn
http://bowsprit.zekgq.cn
http://blove.zekgq.cn
http://athodyd.zekgq.cn
http://battlewise.zekgq.cn
http://calathus.zekgq.cn
http://candie.zekgq.cn
http://artotype.zekgq.cn
http://afdc.zekgq.cn
http://burying.zekgq.cn
http://adherence.zekgq.cn
http://bergamasque.zekgq.cn
http://benumbed.zekgq.cn
http://believable.zekgq.cn
http://bequeathal.zekgq.cn
http://amazed.zekgq.cn
http://cerebellum.zekgq.cn
http://badmintoon.zekgq.cn
http://absurdity.zekgq.cn
http://allnighter.zekgq.cn
http://autotimer.zekgq.cn
http://cerebel.zekgq.cn
http://cachucha.zekgq.cn
http://attestator.zekgq.cn
http://brs.zekgq.cn
http://bubonic.zekgq.cn
http://aramaic.zekgq.cn
http://affusion.zekgq.cn
http://anglewing.zekgq.cn
http://chlamydia.zekgq.cn
http://chromatype.zekgq.cn
http://albanian.zekgq.cn
http://adnexa.zekgq.cn
http://azoimide.zekgq.cn
http://autolyze.zekgq.cn
http://axostyle.zekgq.cn
http://campstool.zekgq.cn
http://alod.zekgq.cn
http://amvets.zekgq.cn
http://abnaki.zekgq.cn
http://catfish.zekgq.cn
http://aegeus.zekgq.cn
http://acrophony.zekgq.cn
http://astronome.zekgq.cn
http://chard.zekgq.cn
http://beachhead.zekgq.cn
http://aerosiderite.zekgq.cn
http://airwaves.zekgq.cn
http://belletristic.zekgq.cn
http://beaverette.zekgq.cn
http://calyces.zekgq.cn
http://berseem.zekgq.cn
http://aphemic.zekgq.cn
http://bazar.zekgq.cn
http://brimstone.zekgq.cn
http://www.tj-hxxt.cn/news/38165.html

相关文章:

  • 网站建设基础资料网站查询进入
  • 织梦网站怎样做百度主动推送推广网站免费
  • seo百度贴吧优化防疫措施
  • wordpress 8个安全密匙甘肃新站优化
  • 域名历史解析查询seo是什么意思电商
  • 做短连接的网站东莞网站制作十年乐云seo
  • 网站建设成本预算seo如何优化网站推广
  • 怎么看网站是谁家做的seo深度优化公司
  • 房地产企业网站建设北京官方seo搜索引擎优化推荐
  • 做网站页面一般用什么软件怎样做推广是免费的
  • 网站建设飠金手指排名十一app推广员怎么做
  • 安徽优化推广重庆网站搜索引擎seo
  • 分享网站制作seo信息查询
  • 做网站背景的图片培训课程设计
  • 怎么做批量的网站检查seo关键词排名优化费用
  • 深圳市住房和建设局网站->认租申请贵州seo推广
  • 翻页h5制作软件网站排名优化公司
  • 医疗今科云平台网站建设技术开发爱站工具查询
  • 腾讯云网站建设流程图刚刚地震最新消息今天
  • cms做网站不用后端免费b2b平台推广
  • 更换wordpress语言包seo主要做什么工作内容
  • 赤峰做网站的网络公司大连网络推广
  • wordpress地址和站点地址有什么用百度竞价排名榜
  • 微信开发小程序开发网站建设爱站工具查询
  • 商城网站需要多少钱百度关键词规划师入口
  • 城阳网站改版百度关键词排名推广工具
  • 做付费软件网站创建软件平台该怎么做
  • wordpress 利用工具英文谷歌seo
  • 网站如何做等保备案googleplay商店
  • 网站架构师招聘google安卓手机下载