Stack Remove method bug?
Monkey Forums/Monkey Programming/Stack Remove method bug?
| ||
| (V40) Should the Stack Remove method return an integer or the 'value'/object at a given index? In my application, I would have expected the following line to be valid but monkey is wanting to return an integer value, rather than a Card object, and thus won't compile. Local c:Card = pack.Remove(i) EDIT: (My 'pack' Stack is declared and initialized with Card instances, and my other 'pack'- related code functions as expected.) I'll post some runnable code if that will help. |
| ||
| Hi, > In my application, I would have expected the following line to be valid Why? The docs don't say anything about returning the removed object... I guess it'd be more consistent with List's RemoveFirst/RemoveLast if it did though...will have a think about it. |
| ||
| Hi, Oops...moved this without leaving a note in bug reports... |
| ||
| I was thinking of 'Remove' as a sort of opposite to the 'Insert' method, which similarly operates on an index value. It's no big deal, I just wondered if Remove should return the removed 'object' or not. I had planned on using it for my stack shuffling method like so:
For Local n:Int = 1 To pack.Length()
Local i:Int = Floor(Rnd(pack.Length()))
Local c:Card = pack.Remove(i)
i = Floor(Rnd(pack.Length()))
pack.Insert(i, c)
Next
But there are other ways:
For Local n:Int = 1 To (pack.Length() * 2)
Local c:Card = pack.Pop()
Local i:Int = Floor(Rnd(pack.Length()))
pack.Insert(i, c)
Next
|