C ++中的堆栈弹出/推入程序 [英] Stack Pop/Push Program in C++

查看:69
本文介绍了C ++中的堆栈弹出/推入程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想开发堆栈弹出/推入程序...
我需要有关如何制作此程序的想法....

hey,,,everyone

i want to develop stack pop/push program ...
i need idea to how to make this program....

推荐答案

如果必须从头开始,则只需要一个数组和一个整数. br/> 创建数组,使其足够大以应付您的预期需求,并将整数设置为零.
在您的Push功能中:
1)检查整数是否与数组的大小相同.如果是这样,则会出错-堆栈溢出.
2)将您的值插入到数组的整数位置.递增整数:
If you have to do it from scratch, all you need is an array and a integer.
Create the array so that it is big enough to cope with your expected demand, and set the integer to zero.
In your Push function:
1) Check if the integer is the same as the size of the array. If so, error - stack overflow.
2) Insert your value to the array, at the position of the integer. Increment the integer:
mystack[index++] = value;



在您的Pop函数中:
1)检查整数是否为零.如果是,则报错-堆栈下溢.
2)减少整数,然后删除该位置的值:



In your Pop function:
1) Check if the integer is zero. If it is, error - stack underflow.
2) Reduce the integer, and remove the value at that position:

value = mystack[--index];


这篇关于C ++中的堆栈弹出/推入程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆