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

1. ## 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.
- What is Enqueue(Q,'A')?

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

2. 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.

3. Originally Posted by Mr.777
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. Originally Posted by ee1215
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. Originally Posted by Mozza314
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.