Pushing a Queue Onto Stack

This is a discussion on Pushing a Queue Onto Stack within the C Programming forums, part of the General Programming Boards category; Hey, I'm having a problem pushing a queue into a stack and Im stuck at how to fix it. Here ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    3

    Pushing a Queue Onto Stack

    Hey, I'm having a problem pushing a queue into a stack and Im stuck at how to fix it.

    Here is my function that adds a queue into the stack
    Code:
    void add_new_queue(struct stack* s, struct queue* q)
    {
        if(s->top == s->size)
            expand_stack(s);
            
        s->store[s->top] = q->store[q->front] ;    
        s->top++;
    }
    I know its in the underlined part, I just dont know what to assign to the stack.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    This seems ... familiar ... strangely familiar ... Do the words "struct queue" appear anywhere in your definition of "struct stack"? If not, why not?

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    3
    yeah it does
    Code:
    struct stack
    {
        struct queue* store;
        int top; 
        int size; 
    };

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So you need to set that left-hand side equal to a struct queue. As you can tell from the function header, "*q" is a struct queue. So maybe that's what you should set the left-hand side equal to.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    3
    That seemed to have worked, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 09:17 AM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. Pushing a Queue onto a Stack?
    By MiroMage in forum C Programming
    Replies: 5
    Last Post: 10-14-2008, 10:23 PM
  4. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-12-2006, 12:41 AM
  5. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21