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
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,
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
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