Skip to content

Instantly share code, notes, and snippets.

@ZiKT1229
Last active July 25, 2018 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZiKT1229/21f6f5d3aa4ab21d5153e60838b78045 to your computer and use it in GitHub Desktop.
Save ZiKT1229/21f6f5d3aa4ab21d5153e60838b78045 to your computer and use it in GitHub Desktop.
stack and queue with c++
#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;
}
#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