Thread: Help with understanding Push/Pop and Enqueue/Dequeue

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    14

    Help with understanding Push/Pop and Enqueue/Dequeue

    I have two different questions for each, Stack and Queue.

    1) Variable S of type Stack. Add the value 12 to the stack S.
    So, I believe the answer would be S.Push(12);
    -What is the difference in S.Push(12) and Push(S,12)?

    2) Variable S of type Stack. Removes top value from the stack S.
    I believe the answer to be S.Pop();
    - I am confused on whether it would be S.Pop() or Pop(S). What is the difference?

    3)Variable Q of type CQueue. Adds value 'A' to the queue Q.
    My answer is: Q.Enqueue('A').
    - What is Enqueue(Q,'A')?

    4) Variable Q of type CQueue. Removes value from queue Q storing it in the char variable C.
    My answer: C=Q.Dequeue();
    - I am little confused on this. What is C=Dequeue(Q)?

  2. #2
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    1. Depends upon the function you've implemented for your class stack.
    2. Depends upon the function you've implemented for your class stack.
    3. Depends upon the function you've implemented for your class queue.
    4. Depends upon the function you've implemented for your class queue.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    14
    Quote Originally Posted by Mr.777 View Post
    1. Depends upon the function you've implemented for your class stack.
    2. Depends upon the function you've implemented for your class stack.
    3. Depends upon the function you've implemented for your class queue.
    4. Depends upon the function you've implemented for your class queue.
    These are multiple choice questions. Nothing to do with coding. Here is an example of the first question and the others are almost identical:

    Suppose that a client function contains a variable S of type Stack. Which of the following statements correctly adds the value 12 to the stack S?
    A) S.Pop(); B) S.Pop(12); C) Push(S,12); D) S.Push(12); E) None of above.

    My answers for each are in the first post.

  4. #4
    C++ Junkie Mozza314's Avatar
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    174
    Quote Originally Posted by ee1215 View Post
    What is the difference in S.Push(12) and Push(S,12)?
    The first one can be used if there is a member function of Stack called "Push", the second can be used if there is a regular function (the type you learn about before learning about member functions) which takes a Stack as a parameter as well as the value to push.

    i.e. S.Push(12) can be used if something like this is in the code:

    Code:
    class Stack
    {
    private
        ...
    
    public:
        ...
        void Push(int x);
        ...
    }
    Push(S, 12) can be used if something like this is in the code:

    Code:
    void Push(Stack& s, int x)
    {
        ...
    }

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    14
    Quote Originally Posted by Mozza314 View Post
    The first one can be used if there is a member function of Stack called "Push", the second can be used if there is a regular function (the type you learn about before learning about member functions) which takes a Stack as a parameter as well as the value to push.

    i.e. S.Push(12) can be used if something like this is in the code:

    Code:
    class Stack
    {
    private
        ...
    
    public:
        ...
        void Push(int x);
        ...
    }
    Push(S, 12) can be used if something like this is in the code:

    Code:
    void Push(Stack& s, int x)
    {
        ...
    }

    Ok, so looks like the Push(S,12) , Enqueue(Q,'A') and such I will not be using.

Popular pages Recent additions subscribe to a feed