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 = Maxsize - 1, end = start, tag = 0; };
- void enqueue(int);
- void dequeue();
- private:
- int start, end, tag;
- int array[Maxsize];
- };
- void queue::enqueue(int in){
- if (start == end&&tag == 1)
- cout << "Queue is full" << endl;
- else{
- end = (end + 1) % Maxsize;
- array[end] = in;
- if (start == end)
- {
- tag = 1;
- }
- }
- }
- void queue::dequeue(){
- if (start ==end && tag==0)
- cout << "η©ΊδΊ" << endl;
- else{
- start=(start+1)%Maxsize;
- cout << "item" << array[start] << "delete" << endl;
- if (start == end)
- tag = 0;
- }
- }
- int main()
- {
- queue s1;
- s1.init();
- for (int i = 1; i < 4; i++)
- {
- int n;
- cout << "please enter the item" << endl;
- cin >> n;
- s1.enqueue(n);
- }
- for (int i = 1; i < 3; i++)
- s1.dequeue();
- for (int i = 1; i < 6; i++)
- {
- int n;
- cout << "please enter the item" << endl;
- cin >> n;
- s1.enqueue(n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement