C + + Queue basic Features

Source: Internet
Author: User

/*

Sichuan Engineering Vocational and Technical College

15 Software

*/

#include <string>
#include <assert.h>
#include <iostream>
typedef int status;
#define OK 1
#define ERROR 0
Template<class type>
Class Order_tream
{

Public
Order_tream (int a): Size (a+1), n (0)
{
Base =new type [a+1];
ASSERT (base!=0);
front=0;
rear=0;
}
int n;
Status full ();//Determine if the
status empty ();//Determine if empty
void Putin (int a);//input
Status Enqueue (Type a);//Incoming queue
Status Sqqueue (type &a);//OUT queue
void clear ();//Empty
Status out ();//Output entire queue
Private
int rear;//Tail
int front;//Head
int size;
type* Base;
};
/* Enter Queue */
Template<class type>
Status Order_tream<type>::enqueue (Type a)
{
if (full ())
return ERROR;
Base[rear]=a;
Rear= (rear+1)%size;
n++;
return OK;
}
/* Empty */
Template<class type>
void Order_tream<type>::clear ()
{
Front=rear;
}
/* Input */
Template<class type>
void Order_tream<type>::p utin (int a)
{
Type X;
cout<< "Input Start" <<endl;
for (int i=0;i<a;i++)
{
cin>>x;
Enqueue (x);
}
}
/* Out of queue */
Template<class type>
Status Order_tream<type>::sqqueue (type& a)
{
if (empty ())
return ERROR;
A=base[front];
Front= (front+1)%size;
n--;
return OK;
}
/* Determine if it is empty */
Template<class type>
Status Order_tream<type>::empty ()
{
if (front==rear)
return OK;
Else
return ERROR;
}
/* Determine if it is full */
Template<class type>
Status Order_tream<type>::full ()
{
if (front==rear+1)
return OK;
Else
return ERROR;
}
/* Output Entire queue */
Template<class type>
Status Order_tream<type>::out ()
{
if (empty ())
return ERROR;
Type A;
for (int i=0;i<n;i++)
{
A=base[i];
cout<<a<< ' \ t ';
}
cout<<n;
cout<<endl;
return OK;
}

C + + Queue basic Features

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.