Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread Prem Nagarajan
I think there is a problem in this solution. U r accessing stack elements from 1 to n in the outer loop. It is not possible. 1st element cannot be accessed without popping first n-1 elements out. On Mon, Jun 18, 2012 at 11:33 AM, Rituraj wrote: > My iterative approach > > /*code in c*/ > #includ

Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread aditya gupta
this is not a stack at all, u have just named it as a stack. for it to be a stack u should access only the top most element at any point of time!!! On Mon, Jun 18, 2012 at 11:33 AM, Rituraj wrote: > My iterative approach > > /*code in c*/ > #include > int main() > { > int stack[]={1,2,3,4,5,6,

Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread Abhishek Sharma
In a stack, you can't access any element directly, except the top one. On Mon, Jun 18, 2012 at 11:33 AM, Rituraj wrote: > My iterative approach > > /*code in c*/ > #include > int main() > { > int stack[]={1,2,3,4,5,6,7,8},top=7;// > int i,j,temp; > > for(i=1;i<=top;i++) > { > temp=stack[i

[algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-17 Thread Rituraj
My iterative approach /*code in c*/ #include int main() { int stack[]={1,2,3,4,5,6,7,8},top=7;// int i,j,temp; for(i=1;i<=top;i++) { temp=stack[i]; for(j=i;j>0;j--) stack[j]=stack[j-1]; stack[0]=temp; } for(i=0;i<=top;i++) printf("%d ",stack[i] ); return 0; } /* Ritu