Last active
July 25, 2018 08:11
-
-
Save ZiKT1229/21f6f5d3aa4ab21d5153e60838b78045 to your computer and use it in GitHub Desktop.
stack and queue with c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <queue> | |
using namespace std; | |
int main() | |
{ | |
queue<int> myQueue; | |
for (int i=0; i<5; i++) | |
myQueue.push(i); //放數字進去 | |
while (!myQueue.empty()) | |
{ | |
cout<<myQueue.front()<<endl; //輸出最前面的數字 | |
myQueue.pop(); //排出最前面的數字 | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stack> | |
using namespace std; | |
int main() | |
{ | |
stack<int> myStack; | |
for (int i=0; i<5; i++) | |
myStack.push(i); //放數字進去 | |
while (!myStack.empty()) | |
{ | |
cout<<myStack.top()<<endl; //輸出最上層的數字 | |
myStack.pop(); //排出最上層的數字 | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment