顺序栈定义练习
来源:互联网 发布:阿里巴巴一键铺货淘宝 编辑:程序博客网 时间:2024/04/30 16:02
#include<stdio.h>#include<stdlib.h>//顺序栈练习#define MaxSize 100#define ElemType inttypedef struct {ElemType data[MaxSize];int top;}SqStack;//top初始值为-1,top总是指向栈顶,top=max-1即为栈满,top=-1即为栈空,进top++,出top--//区分好栈指针和栈顶指针void Init(SqStack *&s){s = (SqStack *)malloc(sizeof(SqStack));s->top = -1;}void Delete(SqStack *&s){free(s);}bool Empty(SqStack *s){return (s->top == -1);}bool Push(SqStack *&s,ElemType e){if (s->top == MaxSize - 1)return false;s->top++;s->data[s->top] = e;return true;}bool Pop(SqStack *&s, ElemType &e){if (s->top == -1)return false;e = s->data[s->top];s->top--;return true;}//出栈,对栈进行改动bool GetTop(SqStack *s, ElemType &e){if (s->top == -1)return false;e = s->data[s->top];return true;}//只是获取栈顶元素值//判断回文练习bool pan(char str[]){int i; char e; SqStack *st;Init(st);for (i = 0; str[i] != '\0'; i++){Push(st, str[i]);}for (i = 1; str[i] != '\0'; i++){Pop(st,e);if (e != str[i]){return false;}}return true;}
阅读全文
0 0
- 顺序栈定义练习
- 栈表定义练习
- 顺序栈类定义
- 顺序栈的自我练习
- 动态顺序栈的定义
- 《数据结构》有关顺序栈的练习
- 顺序栈类模板的定义
- 顺序栈的定义与初始化
- (二)顺序栈函数定义
- c++ 数据结构 顺序栈的类定义
- 顺序栈的定义及相关操作
- 顺序栈的定义和基本算法
- 顺序表的练习
- 顺序表练习
- 顺序表练习代码
- Scala练习-顺序查找
- 练习 2.3 定义矩形
- 定义函数 练习
- 按钮布局演示
- 判断是否相同的二叉搜索树
- WhatWeb源码分析之lib/target.rb
- orbslam 源码分析(五)
- oracle 12c连接cdb&pdb
- 顺序栈定义练习
- Android studio常见故障排除--ADB Connection Error
- CSS3圆角
- java笔记10.28/10.29
- [BZOJ3887][Usaco2015 Jan]Grass Cownoisseur(tarjan+spfa)
- 【bzoj1834】 network 网络扩容 【ZJOI2010】
- 【git 使用详解(5)】– get log 查看提交历史
- 基于Unity 5的次世代卡通渲染技术 -- Unite 2017 米哈游总监贺甲分享实录
- Android HIDL 官方文档(六)—— 使用 Binder 进程间通信机制(Using Binder IPC)