中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

題庫網(wǎng)站建設(shè)seo快速排名是什么

題庫網(wǎng)站建設(shè),seo快速排名是什么,asp源碼 自助建站,做網(wǎng)站怎樣做全頁面文章目錄前言一、棧1.1 棧的概念結(jié)構(gòu)1.2棧的實(shí)現(xiàn)二、隊(duì)列2.1隊(duì)列的概念及結(jié)構(gòu)2.2隊(duì)列的實(shí)現(xiàn)三、棧和隊(duì)列面試題總結(jié)前言 一、棧 1.1 棧的概念結(jié)構(gòu) 棧也是一種線性表,數(shù)據(jù)在邏輯上挨著存儲(chǔ)。只允許在固定的一端進(jìn)行插入和刪除元素。進(jìn)行插入和刪除操作的一端叫棧頂…

文章目錄

  • 前言
  • 一、棧
    • 1.1 棧的概念結(jié)構(gòu)
    • 1.2棧的實(shí)現(xiàn)
  • 二、隊(duì)列
    • 2.1隊(duì)列的概念及結(jié)構(gòu)
    • 2.2隊(duì)列的實(shí)現(xiàn)
  • 三、棧和隊(duì)列面試題
  • 總結(jié)


前言

一、棧

1.1 棧的概念結(jié)構(gòu)

棧也是一種線性表,數(shù)據(jù)在邏輯上挨著存儲(chǔ)。只允許在固定的一端進(jìn)行插入和刪除元素。進(jìn)行插入和刪除操作的一端叫棧頂,另一端叫棧底。符合LIFO 先進(jìn)后出。
在這里插入圖片描述

壓棧:插入操作。
出棧:刪除操作。

1.2棧的實(shí)現(xiàn)

棧的實(shí)現(xiàn)用數(shù)組實(shí)現(xiàn)更好,因?yàn)橥昝婪蠑?shù)組的尾插尾刪。
數(shù)組的緩存利用率高一點(diǎn)。
在這里插入圖片描述
小練習(xí):
在這里插入圖片描述

支持動(dòng)態(tài)增長的棧:

typedef int STDataType;
typedef struct Stack
{STDataType* _a;int _top; // 棧頂int _capacity; // 容量
}Stack;

初始化棧:

void StackInit(ST* ps)
{assert(ps);ps->a = NULL;ps->top = ps->capacity = 0;
}

入棧:進(jìn)棧(棧的插入操作),若棧未滿,則將x加入使之成為新棧頂。

void StackPush(ST* ps, STDataType x)
{assert(ps);if (ps->top == ps->capacity){int newCapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;STDataType* tmp = (STDataType*)realloc(ps->a, newCapacity * sizeof(STDataType));if (tmp == NULL){perror("realloc fail");exit(-1);}ps->a = tmp;ps->capacity = newCapacity;}ps->a[ps->top] = x;ps->top++;
}

出棧:出棧(棧的刪除操作),若棧非空,則彈出棧頂元素,并用x返回。

void StackPop(ST* ps)
{assert(ps);assert(!StackEmpty(ps));--ps->top;
}

獲取棧頂元素:

STDataType StackTop(ST* ps)
{assert(ps);assert(!StackEmpty(ps));return ps->a[ps->top - 1];
}

獲取棧中有效元素個(gè)數(shù):

int StackSize(ST* ps)
{assert(ps);return ps->top;
}

銷毀棧:棧銷毀,并釋放占用的存儲(chǔ)空間

void StackDestroy(ST* ps)
{assert(ps);free(ps->a);ps->a = NULL;ps->capacity = ps->top = 0;
}

檢測棧是否為空,如果為空返回非零結(jié)果,如果不為空返回0:

bool StackEmpty(ST* ps)
{assert(ps);return ps->top == 0;
}
Stack.h
#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>
typedef int STDataType;
typedef struct Stack
{STDataType* a;int top;int capacity;
}ST;void StackInit(ST* ps);
void StackDestroy(ST* ps);
void StackPush(ST* ps, STDataType x);
void StackPop(ST* ps);
STDataType StackTop(ST* ps);
bool StackEmpty(ST* ps);
int StackSize(ST* ps);
Stack.c
#include "Stack.h"void StackInit(ST* ps)
{assert(ps);ps->a = NULL;ps->top = ps->capacity = 0;
}void StackDestroy(ST* ps)
{assert(ps);free(ps->a);ps->a = NULL;ps->capacity = ps->top = 0;
}void StackPush(ST* ps, STDataType x)
{assert(ps);if (ps->top == ps->capacity){int newCapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;STDataType* tmp = (STDataType*)realloc(ps->a, newCapacity * sizeof(STDataType));if (tmp == NULL){perror("realloc fail");exit(-1);}ps->a = tmp;ps->capacity = newCapacity;}ps->a[ps->top] = x;ps->top++;
}void StackPop(ST* ps)
{assert(ps);assert(!StackEmpty(ps));--ps->top;
}STDataType StackTop(ST* ps)
{assert(ps);assert(!StackEmpty(ps));return ps->a[ps->top - 1];
}bool StackEmpty(ST* ps)
{assert(ps);return ps->top == 0;
}int StackSize(ST* ps)
{assert(ps);return ps->top;
}

二、隊(duì)列

2.1隊(duì)列的概念及結(jié)構(gòu)

隊(duì)列:只允許在一端進(jìn)行插入數(shù)據(jù)操作,在另一端進(jìn)行刪除數(shù)據(jù)操作的特殊線性表,隊(duì)列具有先進(jìn)先出FIFO(First In First Out)
入隊(duì)列:進(jìn)行插入操作的一端稱為隊(duì)尾。
出隊(duì)列:進(jìn)行刪除操作的一端稱為隊(duì)頭。

2.2隊(duì)列的實(shí)現(xiàn)

隊(duì)列用鏈表的結(jié)構(gòu)實(shí)現(xiàn)更優(yōu)

在這里插入圖片描述

鏈?zhǔn)浇Y(jié)構(gòu):表示隊(duì)列

typedef struct QListNode
{ struct QListNode* _pNext; QDataType _data; 
}QNode;

隊(duì)列的結(jié)構(gòu):

typedef struct Queue
{QNode* head;QNode* tail;int size;
}Queue;

初始化隊(duì)列:

void QueueInit(Queue* pq)
{assert(pq);pq->head = pq->tail = NULL;pq->size = 0;
}

隊(duì)尾入隊(duì)列:

void QueuePush(Queue* pq, QDataType x)
{assert(pq);QNode* newnode = (QNode*)malloc(sizeof(QNode));if (newnode == NULL){perror("malloc fail");exit(-1);}else{newnode->data = x;newnode->next = NULL;}if (pq->tail == NULL){pq->head = pq->tail = newnode;}else{pq->tail->next = newnode;pq->tail = newnode;}pq->size++;
}

隊(duì)頭出隊(duì)列:

void QueuePop(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));if (pq->head->next == NULL){free(pq->head);pq->head = pq->tail = NULL;}else{QNode* del = pq->head;pq->head = pq->head->next;free(del);del = NULL;}pq->size--;
}

獲取隊(duì)列頭部元素:

QDataType QueueFront(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->head->data;
}

獲取隊(duì)列隊(duì)尾元素:

QDataType QueueBack(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->tail->data;
}

獲取隊(duì)列中有效元素個(gè)數(shù):

int QueueSize(Queue* pq)
{assert(pq);return pq->size;
}

檢測隊(duì)列是否為空,如果為空返回非零結(jié)果,如果非空返回0:

bool QueueEmpty(Queue* pq)
{assert(pq);return pq->head == NULL && pq->tail == NULL;
}

銷毀隊(duì)列:

void QueueDestroy(Queue* pq)
{assert(pq);QNode* cur = pq->head;while (cur){QNode* del = cur;cur = cur->next;free(del);}pq->head = pq->tail = NULL;
}
Queue.h
#pragma once
#include <stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>typedef int QDataType;
typedef struct QueueNode
{struct QueueNode* next;QDataType data;
}QNode;typedef struct Queue
{QNode* head;QNode* tail;int size;
}Queue;void QueueInit(Queue* pq);
void QueueDestroy(Queue* pq);
void QueuePush(Queue* pq, QDataType x);
QDataType QueueFront(Queue* pq);
QDataType QueueBack(Queue* pq);
bool QueueEmpty(Queue* pq);
int QueueSize(Queue* pq);
Queue.c
#include"Queue.h"void QueueInit(Queue* pq)
{assert(pq);pq->head = pq->tail = NULL;pq->size = 0;
}void QueueDestroy(Queue* pq)
{assert(pq);QNode* cur = pq->head;while (cur){QNode* del = cur;cur = cur->next;free(del);}pq->head = pq->tail = NULL;
}void QueuePush(Queue* pq, QDataType x)
{assert(pq);QNode* newnode = (QNode*)malloc(sizeof(QNode));if (newnode == NULL){perror("malloc fail");exit(-1);}else{newnode->data = x;newnode->next = NULL;}if (pq->tail == NULL){pq->head = pq->tail = newnode;}else{pq->tail->next = newnode;pq->tail = newnode;}pq->size++;
}void QueuePop(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));if (pq->head->next == NULL){free(pq->head);pq->head = pq->tail = NULL;}else{QNode* del = pq->head;pq->head = pq->head->next;free(del);del = NULL;}pq->size--;
}QDataType QueueFront(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->head->data;
}QDataType QueueBack(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->tail->data;
}bool QueueEmpty(Queue* pq)
{assert(pq);return pq->head == NULL && pq->tail == NULL;
}int QueueSize(Queue* pq)
{assert(pq);return pq->size;
}

三、棧和隊(duì)列面試題

題目鏈接:
1.https://leetcode.cn/problems/valid-parentheses/
在這里插入圖片描述

在這里插入圖片描述

題目鏈接:
2.https://leetcode.cn/problems/implement-stack-using-queues/

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

總結(jié)

http://www.risenshineclean.com/news/6463.html

相關(guān)文章:

  • 集寧做網(wǎng)站的公司電商是做什么的
  • 學(xué)做軟件的網(wǎng)站有哪些網(wǎng)頁制作與網(wǎng)站建設(shè)實(shí)戰(zhàn)教程
  • 國外男女直接做的視頻網(wǎng)站中國目前最好的搜索引擎
  • 北京市公司網(wǎng)站制作教育培訓(xùn)機(jī)構(gòu)推薦
  • 網(wǎng)站開發(fā)測試百度手機(jī)助手app免費(fèi)下載
  • 惠州網(wǎng)站建設(shè)seo網(wǎng)站怎么搭建
  • 做網(wǎng)站 鄭州公司哪家好seo怎么收費(fèi)
  • 上海網(wǎng)站建設(shè)專業(yè)公司自然搜索優(yōu)化
  • 鄄城網(wǎng)站建設(shè)哪家好網(wǎng)上有免費(fèi)的網(wǎng)站嗎
  • google網(wǎng)站怎么做流量app推廣項(xiàng)目從哪接一手
  • 交友a(bǔ)pp搭建seo就業(yè)指導(dǎo)
  • 怎么做網(wǎng)站圖標(biāo)電商平臺(tái)運(yùn)營方案
  • 大型網(wǎng)站設(shè)計(jì)公司站長素材音效
  • 湛江有幫公司做網(wǎng)站營銷型網(wǎng)站更受用戶歡迎的原因是
  • 公眾號(hào)后端框架網(wǎng)站seo排名優(yōu)化價(jià)格
  • 無錫做智能網(wǎng)站流量精靈官網(wǎng)
  • 做問卷的網(wǎng)站有哪些內(nèi)容貼吧友情鏈接在哪
  • 北海哪家做網(wǎng)站百度推廣怎么做
  • 個(gè)人網(wǎng)站官網(wǎng)如何建立免費(fèi)公司網(wǎng)站
  • 網(wǎng)站建設(shè)的威脅seo百度點(diǎn)擊軟件
  • 北京學(xué)生做兼職的網(wǎng)站電子郵件營銷
  • 做的比較好看的國內(nèi)網(wǎng)站怎么制作個(gè)人網(wǎng)站
  • 使用java做新聞網(wǎng)站思路深圳搜索競價(jià)賬戶托管
  • 成都網(wǎng)站建設(shè)制作價(jià)格有人看片嗎免費(fèi)的
  • 建設(shè)銀行銀行社會(huì)招聘網(wǎng)站在線域名解析ip地址
  • 網(wǎng)站活動(dòng)平臺(tái)推廣計(jì)劃網(wǎng)絡(luò)域名怎么查
  • 河南做網(wǎng)站 河南網(wǎng)站建設(shè)seo營銷
  • 項(xiàng)目建設(shè)資金來源網(wǎng)站網(wǎng)站百度收錄批量查詢
  • emblog詳細(xì)轉(zhuǎn)wordpress福州seo網(wǎng)站推廣優(yōu)化
  • 做網(wǎng)站代理屬于開設(shè)賭場罪嗎國內(nèi)搜索網(wǎng)站排名