如何用数组实现堆栈? [英] How to implement a stack with an array?

查看:171
本文介绍了如何用数组实现堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我想用数组实现堆栈,请帮帮我! (é_è)

谢谢

解决方案

此GeeksPlanet 解决方案

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屋!

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