王道计算机考研 数据结构C语言复现-第五章-栈

这篇文章收录了王道考研课程中涉及的数据结构的所有代码。此外,本博客可能会添加一些额外的代码(不仅限于王道考研),因为408考试中会频繁考察一些冷门的知识点,所以这篇博客会涵盖所有相关的代码。这也是我数据结构的第一轮复习,希望能与大家共同进步。由于博客篇幅的限制,可能无法一次性包含所有内容,欢迎指出代码错误部分!!!

你想要的都在下面!!!

// @FileName  :ZhanandDuiLie.c
// @Time      :2023/8/14 20:09
// @Author    :YKW
#define MaxSize 10
# include <stdio.h>
# include <stdbool.h>
//栈(Stack)是只允许在一段进行插入或删除操作的线性表
//后进先出
//顺序栈
typedef struct{
    int data[MaxSize];//栈内元素
    int top;//栈顶指针,此处是下标
}SqStack;
void InitStack(SqStack *S){
    S->top=-1;
}
//新元素入栈
bool Push(SqStack *S,int x){
    if(S->top==MaxSize-1)//栈满了
        return false;
    S->top=S->top+1;//
    S->data[S->top]=x;
    return true;
}
bool Pop(SqStack *S,int x){
    if(S->top==-1)//栈空
        return false;
    x=S->data[S->top--];
    return true;
}
bool GetTop(SqStack S,int *x){
    if(S.top==-1)
        return false;
    *x=S.data[S.top];//
    return true;
}
bool bracketCheck(char str[],int length){
    SqStack S;
    InitStack(&S);
    for(int i=0;i<length;i++){
        if(str[i]=='('||str[i]=='['||str[i]=='{')
            Push(&S,str[i]);
        else{//右括号
            if(S.top==-1)//栈空&右括号
                return false;
            char topElem;
            Pop(&S,topElem);
            if(str[i]==')'&&topElem!='(')
                return false;
            if(str[i]==']'&&topElem!='[')
                return false;
            if(str[i]=='}'&&topElem!='{')
                return false;
        }
    }
    return S.top==-1;
}

//共享栈
typedef struct{
    int data[MaxSize];
    int top1;
    int top2;
}ShStack;

//链栈
typedef struct Linknode{
    int data;
    struct Linknode *next;
} *LiStack;
int main(){

}

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-07 05:48:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-07 05:48:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-07 05:48:04       82 阅读
  4. Python语言-面向对象

    2024-01-07 05:48:04       91 阅读

热门阅读

  1. 信息学奥赛一本通2065:【例2.2】整数的和

    2024-01-07 05:48:04       55 阅读
  2. PostgreSQL相对MySQL有啥区别?

    2024-01-07 05:48:04       53 阅读
  3. 安卓之动画使用场景以及优劣分析

    2024-01-07 05:48:04       50 阅读
  4. python-time模块使用

    2024-01-07 05:48:04       56 阅读
  5. 前端实现回车键触发搜索

    2024-01-07 05:48:04       58 阅读
  6. nodejs 实现内部之间接口的相互调用

    2024-01-07 05:48:04       62 阅读
  7. 笔记 | Bash 中 if 判断选项

    2024-01-07 05:48:04       52 阅读
  8. 基于albert的汽车评论情感分析【含代码】

    2024-01-07 05:48:04       43 阅读
  9. MySQL-多表查询

    2024-01-07 05:48:04       73 阅读