栈的学习笔记
来源:互联网 发布:反电信网络诈骗宣传片 编辑:程序博客网 时间:2024/06/07 05:25
坚持就是胜利,加油吧自己
前期数据准备:
#define maxsize 100typedef int elemtype;typedef struct stack_type{elemtype stack[maxsize];int top;}stacktype;
使用函数:
//initialvoid initial(stacktype *p){p->top = -1;//Why is top equal to -1?}//Insert elem;bool push(stacktype *p,elemtype a){if (p->top >= maxsize - 1){printf("This stack IS FULL! Please find another stack to finish your option!!!\n");return false;}else{p->top++;p->stack[p->top] = a;return true;}}//Let the top elem get out of the stackelemtype pop(stacktype *p){if (p->top < 0){printf("This stack IS EMPTY!Please find another stack to finish your option!!!\n");return(NULL);}else{p->top--;return(p->stack[p->top + 1]);}}
使用该栈解决的问题:简单的数字进制转换
我的代码:
#include <cstdio>#include <iostream>using namespace std;#define maxsize 100typedef int elemtype;typedef struct stack_type{elemtype stack[maxsize];int top;}stacktype;//void initial(stacktype *p){p->top = -1;//Why is top equal to -1?}//Insert elem;bool push(stacktype *p,elemtype a){if (p->top >= maxsize - 1){printf("This stack IS FULL! Please find another stack to finish your option!!!\n");return false;}else{p->top++;p->stack[p->top] = a;return true;}}//Let the top elem get out of the stackelemtype pop(stacktype *p){if (p->top < 0){printf("This stack IS EMPTY!Please find another stack to finish your option!!!\n");return(NULL);}else{p->top--;return(p->stack[p->top + 1]);}}int main(void){stacktype s,*p;p = &s;//Now here is a simple question ;elemtype num = 12;int choice; bool flag;scanf_s("%d",&choice);initial(p);do{flag = push(p, (num%choice));} while ((num/=choice)&&flag);printf("\nNow the ans is ");while (p->top >= 0){printf("%d",pop(p));}cout << endl;return 0;}
输出结果
0 0
- 栈的学习笔记
- VLAN学习笔记的笔记
- 学习深度学习的笔记
- 学习机器学习的笔记
- 数据结构学习笔记 --- 栈的应用举例
- 【学习笔记----数据结构06-栈的应用】
- 数据结构学习笔记 --- 栈的应用举例
- BLE协议栈的学习笔记
- C++的学习笔记
- 学习Java的笔记
- SNMP的学习笔记
- InstantObjects 的学习笔记
- ASM的学习笔记
- 学习C#的笔记
- DBGridEh的学习笔记
- DBGridEh的学习笔记
- 学习HTML的笔记
- Oracle的学习笔记
- VHDL 的UART 的实现
- 关于 36 氪
- lightoj1148 - Mad Counting
- 计算机硬件
- CMake学习
- 栈的学习笔记
- 横竖屏切换时候Activity的生命周期的总结
- Socket通信readObject()方法出现异常
- Android build.prop 添加自定义项 及使用
- Android第三方网络资源加载框架Volley
- 多个线程顺序进行和轮询进行的问题
- LeetCode56——Merge Intervals
- 机器学习之特征工程
- python regex 入门笔记