Results 1 to 6 of 6

Thread: Getting problem in stack and unstack view

  1. #1
    Join Date
    Dec 2009
    Posts
    59

    Getting problem in stack and unstack view

    Hello friend,

    I have a program that doesn't work properly, it is related to stack and unstack stack and relies display. Everything is fine except that when I pile more data and I posters, I think the last repeat several times. Here are the complete code:
    Code:
    # include <conio.h> 
    # include <stdio.h>    
    # include <stdlib.h>      
    typedef struct element1 
                {
                           int data1;
                           struct element1 * prev1;
                }link;
    typedef link * Stack;
    Stack stack(Pile MAPIL1,int GIVEN)
    {
    Pile nv1 =(Pile)malloc(sizeof(link));
         nv1-> data1 = data1;
         nv1-> prev1 = MAPIL1;
         MAPIL1 = nv1;
         return MAPIL1;
    }
    Stack unstack(Pile MAPIL1)
    {
         if(MAPIL1 ==NULL)
           {
                         printf("Stack is empty");
                         return NULL;
           }
           if(MAPIL1-> prev1 ==NULL)
           {
                                      free(MAPIL1);
                                      return NULL;
           }
           
           
         Pile nv1Sommet = MAPIL1-> prev1;
         free(MAPIL1);
         return nv1Sommet;
    }
    void affichePile(Pile MAPIL1)
    {
         if(MAPIL1 ==NULL)
         printf("There is nothing to display");
        else
        {
        Tmp = stack MAPIL1;
        
            while(tmp! =NULL)
         {
                         printf("% d", MAPIL1-> data1);
                         tmp = tmp-> prev1;
         }
         }
    }
     
    int hand11()
    {
        Pile MAPIL1 =NULL;
        MAPIL1 = stack(MAPIL1,1);
        MAPIL1 = stack(MAPIL1,2);
        MAPIL1 = stack(MAPIL1,3);
        MAPIL1 = stack(MAPIL1,4);
        affichePile(Pile MAPIL1)
     
    }
    Please help me over this.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Getting problem in stack and unstack view

    Modify your duties stacking and unstacking may allow you to simplify the writing. During the first stack, your stack function gives a value to "MAPIL1". In the following stacks, it continues your linked list, as you do, without changing "MAPIL1". When you depilation, unstacking function performs the inverse operation. If you unstack the only remaining value, the function returns the value you "MAPIL" to NULL:
    stack(& MAPIL1,2);
    stack(& MAPIL1,3);
    (...)

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Getting problem in stack and unstack view

    Hello friend,

    I suggest you to use "tmp" in stead of "MAPIL" in some section of your program code, seer below:
    Your code:
    while (tmp! = NULL)
    (
    printf ( "% d",MAPIL1-> data);
    tmp = tmp-> prev;
    )
    Correct code:
    while (tmp != NULL)
    (
    printf ( "% d", tmp -> data);
    tmp = tmp-> prev1;
    )

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Getting problem in stack and unstack view

    Hi,

    Your program code for stack and unstack view comprises some logical error. That's why you are not getting desired put. According to me you should check the following section of mentioned program, because when I run this program the error message pointed toward this code:
    Code:
        while (tmp! = NULL)
         {
                         printf ( "% d",tmp -> data1);
                         
                    tmp = tmp-> prev1;
        }

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Getting problem in stack and unstack view

    Hi friend,

    It seems that you are trying to display the wrong variable of of the given program. see below:
    Code:
    printf ( "% d",MAPIL1-> data1);// Wrong
    printf ( "% d",tmp1-> data1);// Correct
    Here you need to put the "tmp1" variable instead of "MAPIL1". And then try to re-run the program.

  6. #6
    Join Date
    Dec 2009
    Posts
    59

    Re: Getting problem in stack and unstack view

    Hello friend,

    Thanks for all your reply!!,
    My problem has solved, and it was very simple. This was problem in the logic used in the program. As per you suggestion I used "tmp1" variable instead of "MAPIL1" variable in some statement of my program. Now the program is displaying the desired output and which is stack and unstack view.

Similar Threads

  1. Stack problem with Mac OS X 10.5.2
    By Cherkasov in forum Operating Systems
    Replies: 5
    Last Post: 27-05-2010, 05:03 PM
  2. Services.msc view problem
    By pratikag in forum Operating Systems
    Replies: 3
    Last Post: 05-10-2009, 02:59 PM
  3. Filmstrip view problem in Xp
    By aprnavich in forum Customize Desktop
    Replies: 3
    Last Post: 04-05-2009, 05:58 PM
  4. Problem of View with my graphics card
    By HADLEY in forum Monitor & Video Cards
    Replies: 1
    Last Post: 03-12-2008, 04:58 PM
  5. Bluetooth, Changing from Toshiba stack to MS stack
    By LaKisha in forum Vista Hardware Devices
    Replies: 1
    Last Post: 18-10-2007, 11:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,718,109.05493 seconds with 16 queries