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 <[email protected]> wrote:
> My iterative approach
>
> /*code in c*/
> #include<stdio.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;j>0;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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.