Loop queue (Array storage)

Source: Internet
Author: User

#include <iostream>
using namespace Std;
#define MAXSIZE 100
Class Qune
{
Public
int data[maxsize];
int front;
int rear;
};
void Qinsert (Qune&a,int x); Team
int Qdelete (QUNE&A); Out Team
int main ()
{
Qune A;
A.front = A.rear =-1; Initializing an empty queue
}
void Qinsert (Qune&a,int x)
{
if ((a.rear + 1)% Maxsize = = A.front) {//To determine the queue is full, the maximum number of elements in the queue storage is Maxsize-1
cout << "Queue full";
return;
}
A.rear = (a.rear + 1)% Maxsize; Loop queue, number of insertions at the end of the team
A.data[a.rear] = = x;
}
int Qdelete (QUNE&A)
{
if (a.rear== a.front) {
cout << "queue is empty";
return 0;
}
A.front = (a.front + 1)% Maxsize; Out of the team in front of the team
return A.data[a.front];
}

Loop queue (Array storage)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.