你可以帮我堆栈吗? [英] Can you help me with stacks?

查看:59
本文介绍了你可以帮我堆栈吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很难用Stack ...


问题就是这样:

创建一个数组( a [10])。

如果选择== 1,请按数字。

如果选择== 2,弹出数字,

如果选择== 3,则显示堆栈。

如果选择== 0退出。



请帮助我!

我是新来的堆叠,这就是为什么我遇到了一些困难。

谢谢。

I''m really having a hard time with Stack...

The problem goes this way:

Create an array ( a[10] ).
If choice == 1, push number.
If choice == 2, pop number,
If choice == 3, display stack.
If choice == 0 quit.


Please help me!
I''m new to stacks that''s why I''m having some difficulties.
Thank you.

推荐答案

堆栈是一个采用最后一个队列的队列-in先出策略。


如果您想使用数组来实现堆栈,您必须记住:

1]在堆栈中插入元素(推送)时,可以在元素的第一个可用位置写入元素,确保位置在数组维度内。


2]当你删除一个元素(pop)时,你正在提取插入的最后一个元素,确保堆栈是非空的。


这可以通过保存一个变量来完成数组的最后插入元素的位置,并使用它来查找要弹出的元素或在哪个位置推送新元素。


希望这会有所帮助。
Stack is a queue wich adopt a last-in first-out strategy.

If you would like to use an array to implemet a stack, you have to keep in mind that:
1] When you are inserting an element in the stack (push), you can write the element in the first available position of the array, making sure that the position is within the array dimension.

2] When you are removing an element (pop), you are extracting the last element inserted, making sure the stack is non-empty.

This can be done by keeping in a variable the position of the last inserted element of the array, and using it to find which element to pop or in which position push a new element.

Hope this helps.



Stack是一个采用后进先出策略的队列。
Stack is a queue wich adopt a last-in first-out strategy.



不要非常迂腐(只是一点点):


我会说堆栈是一个列表采用LI-FO,队列是FI-FO结构,恕我直言,定义采用FI-FO策略的LI-FO结构没有多大意义.......

Not to be horribly pedantic (just a little bit):

I would say that a stack is a list which adopts LI-FO, A queue is a FI-FO structure, and IMHO it doesn''t make much sense to define a LI-FO structure which adopts a FI-FO strategy.......



Stack是一个采用后进先出策略的队列。


如果你想使用数组来实现堆栈,你必须记住:

1]当你在堆栈中插入一个元素(推送)时,你可以在第一个可用的位置写入元素数组,确保位置在数组维度内。


2]当你删除一个元素(pop)时,你正在提取插入的最后一个元素,确保堆栈是非空的。


这可以通过在变量中保存数组的最后插入元素的位置,并将其用于f来完成ind要弹出哪个元素或者在哪个位置推送一个新元素。


希望这会有所帮助。
Stack is a queue wich adopt a last-in first-out strategy.

If you would like to use an array to implemet a stack, you have to keep in mind that:
1] When you are inserting an element in the stack (push), you can write the element in the first available position of the array, making sure that the position is within the array dimension.

2] When you are removing an element (pop), you are extracting the last element inserted, making sure the stack is non-empty.

This can be done by keeping in a variable the position of the last inserted element of the array, and using it to find which element to pop or in which position push a new element.

Hope this helps.



感谢您的帮助!

但是,你能帮我制作一个POP,PUSH和DISPLAY堆栈的程序吗?我真的很难过。


请问?


谢谢!

Thanks for the help!
But can you help me make a program that would POP, PUSH and DISPLAY the stack? I''m really having a hard time.

PLEASE?

Thank you!


这篇关于你可以帮我堆栈吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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