Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- #define Maxsize 5
- class queue{
- public:
- void init(){ start = -1, end = -1; };
- void enqueue();
- void dequeue();
- private:
- int start, end;
- int array[Maxsize];
- };
- void queue::enqueue(){
- if (end >= Maxsize - 1)
- cout << "滿了" << endl;
- else{
- end++;
- cout << "請輸入整數" << endl;
- cin >> array[end];
- }
- }
- void queue::dequeue(){
- if (start >= Maxsize - 1)
- cout << "空了" << endl;
- else{
- start++;
- cout << array[start]<<endl;
- }
- }
- int main()
- {
- queue s1;
- s1.init();
- for (int i = 1; i < 7; i++)
- s1.enqueue();
- for (int i = 1; i < 7; i++)
- s1.dequeue();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement