Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication8.cpp : 定義主控台應用程式的進入點。
- //
- #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 arr[maxsize];
- };
- void queue::enqueue(){
- if (end >= maxsize-1){
- cout << "queue is fulled!" << endl;
- }
- else{
- cout << "please enter number to insert: ";
- cin >> arr[++end];
- }
- }
- void queue::dequeue(){
- if (start == end){
- cout << "queue is empty!" << endl;
- return;
- }
- else{
- cout << arr[++start] << endl;
- }
- }
- void main()
- {
- queue Q;
- Q.init();
- int num;
- for (int i = 0; i < 6; i++){
- Q.enqueue();
- }
- for (int i = 0; i < 6; i++){
- Q.dequeue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement