I'm trying to delete every occurrence of a specified item from aStack, leaving the order of the remaining items unchanged. Has anyone done this before or have any ideas. Im pretty sure its possible using the adt operations....
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/** Delete every occurrence of item from aStack.
*
* @pre None.
*
* @post Every element with value item are deleted from aStack and the
* remaining elements are in the same order as they were in the
* stack.
*
* @param aStack Is the stack to delete elements from.
*
* @param item Is the value to remove from aStack. */
deleteItem(inout aStack:Stack, in item:StackItemType)
{
auxStack.createStack()
haha well, I was thinking you would start by popping all the items from aStack, compare top item in the stack to the item and if the top item in the stack is = to the value dont copy the item. Then somehow push everything back onto the stack. I think I have the right idea, I just don't know how to code it!
I see that would work, but that would not be the answer he is looking for. I should have written the question better. You can ONLY use Stack Member Function....
As you know these would be:
· stack::member functions:
· stack::empty
· stack::pop
· stack::push
· stack::size
· stack::top
isnt it an stack, too?.... <- if yes (and you should know wether or not) then it is an stack...
cool, isnt it?:D...
(come on, dont play lazy... we(im schizo, too^^) know you can do it... take a deep breath , take a 5minute breake... read everything after and you should understand...)...
Thanks man, I honestly have read this chapter 2 times and it never mentioned anything about using two stacks, but im sure your right. Ill give it a shot, otherwise there is always the tutoring center in the morning. Thanks alot!
loop:
pop element...
check if it is the one to be excluded...
if yes, dont push it on the auxiliary stack,
if not, push it on the auxiliary stack.
when finished:
loop:
pop from auxstack
push on astack...
because i am bored and cant sleep(its 8 in the morning) i wrote this program to tell you what to do... just follow its instructions and you may be getting what u want...
you could also write an program to take what is between the '' and concatenate it;)...