Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure
In a stack, you can't access any element directly, except the top one. On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote: My iterative approach /*code in c*/ #includestdio.h 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;j0;j--) stack[j]=stack[j-1]; stack[0]=temp; } for(i=0;i=top;i++) printf(%d ,stack[i] ); return 0; } /* Rituraj 2nd Yr. B.tech CSE NIT -Trichy -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/n1OE58e8B7IJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure
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 worstcod...@gmail.com wrote: My iterative approach /*code in c*/ #includestdio.h 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;j0;j--) stack[j]=stack[j-1]; stack[0]=temp; } for(i=0;i=top;i++) printf(%d ,stack[i] ); return 0; } /* Rituraj 2nd Yr. B.tech CSE NIT -Trichy -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/n1OE58e8B7IJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Aditya Gupta B.Tech III yr CSE IITR -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure
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 worstcod...@gmail.com wrote: My iterative approach /*code in c*/ #includestdio.h 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;j0;j--) stack[j]=stack[j-1]; stack[0]=temp; } for(i=0;i=top;i++) printf(%d ,stack[i] ); return 0; } /* Rituraj 2nd Yr. B.tech CSE NIT -Trichy -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/n1OE58e8B7IJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.