stack

  • Thread starter Thread starter Locia
  • Start date Start date
L

Locia

How can I read stack element from top at the bottom?
IEnumerator have only MoveNext() method and I suppone that begin from
the bottom.
 
Locia said:
How can I read stack element from top at the bottom?

Are you using "top" to mean "last added" and "bottom" to mean "first
added" as is normal? (Imagining the stack to be like a stack of plates,
for example.)
IEnumerator have only MoveNext() method and I suppone that begin from
the bottom.

I'm not sure why you suppose that - the stack is defined as a last-in-
first-out collection. Besides, you can very easily test it:

using System;
using System.Collections;

class Test
{
static void Main()
{
Stack stack = new Stack();
stack.Push("First on");
stack.Push("Second on");

foreach (string s in stack)
{
Console.WriteLine (s);
}
}
}

Alternatively, use Pop rather than the enumerator.
 
Stacks are LIFO, Queues are FIFO

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top