Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Implemented push.cpp and pop.cpp to queue #50

Merged
merged 5 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<details>
<summary>View contents</summary>
<ol>
<li><a href="#pop-queue"><code>pop</code></a></li>
<li><a href="#pop"><code>pop</code></a></li>
<li><a href="#back-queue"><code>back</code></a></li>
<li><a href="#push-queue"><code>push</code></a></li>
<li><a href="#push"><code>push</code></a></li>
<li><a href="#size-queue"><code>size</code></a></li>
<li><a href="#swap-queue"><code>swap</code></a></li>
<li><a href="#empty-queue"><code>empty</code></a></li>
Expand All @@ -14,4 +14,50 @@
<li><a href="#queue"><code>queue</code></a></li>
<li><a href="#~queue"><code>~queue</code></a>
</ol>
</details>
</details>

# pop
**Description** : pop() function is used to remove an element from the front of the queue (ie. the oldest element in the queue). The element is removed from the queue container and the size of the queue is decreased by 1.

**Example**:
```cpp
// Empty queue
queue<int> myqueue;

// pushing elements into queue using push()
myqueue.push(0);
myqueue.push(1);
myqueue.push(2);

// pop items from queue
myqueue.pop(); // pops 0 from queue
myqueue.pop(); // pops 1 from queue

// print contents of queue
while (!myqueue.empty()) {
cout << ' ' << myqueue.front();
myqueue.pop();
}
```
**[Run Code](https://rextester.com/XACN77371)**

# push
**Description** : push() function is used to insert an element at the back of the queue. The element is added to the queue container and the size of the queue is increased by 1.

**Example**:
```cpp
// Empty queue
queue<int> myqueue;

// pushing elements into queue using push()
myqueue.push(0);
myqueue.push(1);
myqueue.push(2);

// print contents of queue
while (!myqueue.empty()) {
cout << ' ' << myqueue.front();
myqueue.pop();
}
```
**[Run Code](https://rextester.com/OEC31098)**
29 changes: 29 additions & 0 deletions queue/pop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Rickey Patel
Date : 23/05/2019
Time : 03:50 PM
Description : pop() function is used to remove an element from the front of the queue (ie. the oldest element in the queue). The element is removed from the queue container and the size of the queue is decreased by 1.
*/
#include <iostream>
#include <queue>

int main(){
// Empty queue
std::queue<int> myqueue;

// pushing elements into queue using push()
myqueue.push(0);
myqueue.push(1);
myqueue.push(2);

// pop items from queue
myqueue.pop(); // pops 0 from queue
myqueue.pop(); // pops 1 from queue

// print contents of queue
while (!myqueue.empty()){
std::cout << ' ' << myqueue.front();
myqueue.pop();
}
}
25 changes: 25 additions & 0 deletions queue/push.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Rickey Patel
Date : 23/05/2019
Time : 03:50 PM
Description : push() function is used to insert an element at the back of the queue. The element is added to the queue container and the size of the queue is increased by 1.
*/
#include <iostream>
#include <queue>

int main(){
// Empty queue
std::queue<int> myqueue;

// pushing elements into queue using push()
myqueue.push(0);
myqueue.push(1);
myqueue.push(2);

// print contents of queue
while (!myqueue.empty()){
std::cout << ' ' << myqueue.front();
myqueue.pop();
}
}