R
RobertEstelle
Hello everyone,
I encountered an interesting bug in a program I was writing that was
caused by the following unexpected behaviour. Basically, creating a
new Stack object from another results in a reversal of the item
ordering.
Example:
Stack<string> a = new Stack<string>();
a.Push("a"); a.Push("b"); a.Push("c"); a.Push("d");
// a has "d","c","b","a"
Stack<string> b = new Stack<string>(a);
// b has "a","b","c","d"
Does anyone know why this happens? Is it a bug in the class library,
or some mistaken assumption on my part?
For background, I was using a stack for a recursive function wherein
each function call required its own copy of the initial stack to pop
items off. Needless to say, having the stack reverse itself at each
depth caused some interesting behaviour.
Looking forward to your comments;
- Robert Estelle
I encountered an interesting bug in a program I was writing that was
caused by the following unexpected behaviour. Basically, creating a
new Stack object from another results in a reversal of the item
ordering.
Example:
Stack<string> a = new Stack<string>();
a.Push("a"); a.Push("b"); a.Push("c"); a.Push("d");
// a has "d","c","b","a"
Stack<string> b = new Stack<string>(a);
// b has "a","b","c","d"
Does anyone know why this happens? Is it a bug in the class library,
or some mistaken assumption on my part?
For background, I was using a stack for a recursive function wherein
each function call required its own copy of the initial stack to pop
items off. Needless to say, having the stack reverse itself at each
depth caused some interesting behaviour.
Looking forward to your comments;
- Robert Estelle