如何用数组实现堆栈? [英] How to implement a stack with an array?
本文介绍了如何用数组实现堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
我想用数组实现堆栈,请帮帮我! (é_è)
谢谢
解决方案
此GeeksPlanet ^ ]可能会有所帮助.是发明的(在C发明之前),栈实现很简单.
初始化:声明尺寸堆栈[100](设置堆栈的最大大小)
整数电流= 0;
推送:堆栈[当前++] = data_to_be_saved
弹出:data_restored = stack [-current]
正确的类型,从伪C到真实C/C ++的转换以及处理数据是对象,字符串或整个结构的情况都是学生的练习.
Hi friends,
I want to implement a stack with an array please help me !! (é_è)
thank you
解决方案
This GeeksPlanet article[^] might help.
Back when I was in college, before hardware stacks were invented (and before C was invented), a stack implementation was simply.
Init: declare dimension stack[100] (set the max size of the stack)
integer current = 0;
Push: stack[current++] = data_to_be_saved
Pop: data_restored = stack[--current]
Getting the type right, converting from pseudo-C to real C/C++, and handling cases where the data is an object or string or entire struct are exercises for the student.
这篇关于如何用数组实现堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文