DIR Return Create A Forum - Home
---------------------------------------------------------
techsuns
HTML https://techsuns.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: Puzzles && Algorithms
*****************************************************
#Post#: 126--------------------------------------------------
Re: data structures
By: dinesh Date: November 19, 2012, 12:10 am
---------------------------------------------------------
since there is a necessity for another stack, is there one
available(without us creating)?!?! ???
Think on these lines...
#Post#: 127--------------------------------------------------
Re: data structures
By: ravu Date: November 19, 2012, 12:14 am
---------------------------------------------------------
yeah we can simulate the same thing using recursion- But that
doesn't mean you are using only one stack right?
#Post#: 129--------------------------------------------------
Re: data structures
By: dinesh Date: November 19, 2012, 12:17 am
---------------------------------------------------------
when you solve any problem using recursion, do you say solve
using stack??
#Post#: 130--------------------------------------------------
Re: data structures
By: ravu Date: November 19, 2012, 12:21 am
---------------------------------------------------------
No, I meant recursion takes care of another stack, but still we
are using two stacks. How did we solve the problem using only
one stack?
#Post#: 133--------------------------------------------------
Re: data structures
By: ravu Date: November 19, 2012, 12:46 am
---------------------------------------------------------
@Kp we can't modify or add new operations like remove to stack.
We have to use standard stack operations.
#Post#: 161--------------------------------------------------
Re: data structures
By: kpr29 Date: November 19, 2012, 10:46 pm
---------------------------------------------------------
@Dinesh: If u explain answer it will nice........ before we
shift to other problem............
kp.
#Post#: 173--------------------------------------------------
Re: data structures
By: dinesh Date: November 20, 2012, 12:18 am
---------------------------------------------------------
You can simulate a queue using only one stack. The second
(temporary) stack can be simulated by the call stack of
recursive calls to the insert method.
The pseudocode will contain a single stack.
As some have pointed out, we are still using 2 stacks - one from
the programming language support for recursion!!!
insert(E value)
{
stack.push(value);
}
E remove()
{
E top = stack.pop();
if(stack.isEmpty())
return top;
else
{
E result = remove();
stack.push(top);
return result;
}
}
#Post#: 260--------------------------------------------------
Re: data structures
By: satya Date: November 28, 2012, 11:29 pm
---------------------------------------------------------
@dinesh: can u give the answer for this...as this discussion
ended abruptly......i mean without we knowing the
answer.......... ;D ;D
#Post#: 264--------------------------------------------------
Re: data structures
By: kranthipls Date: November 28, 2012, 11:40 pm
---------------------------------------------------------
@satya: The above pseudo code is the answer. I mean we use only
one stack and deleting is done using recursion.
*****************************************************
DIR Next Page