Basic operations such as initialization of cyclic queues, queue-up, team-out, etc.

Source: Internet
Author: User

The initialization of the loop queue, the team, and other basic operations, the implementation code is as follows:

#include <iostream>

using namespace Std;

#define TRUE 1

#define FALSE 0


Type definitions for circular queues

Maximum length of the MAXSIZE 50//queue #define

typedef struct

{

int element[maxsize];//The element space of the queue

int front;//Head pointer indicator

int rear;//Tail pointer indicator

}seqqueue;


Loop Queue Initialization

void Initqueue (Seqqueue *q)//Initialize *q to an empty loop queue

{

Q->front = q->rear = 0;

}


Queue up the Loop queues

int Enterqueue (seqqueue *q, int x)//queue element x

{

if ((q->rear + 1)% MAXSIZE = = Q->front)//tail pointer plus 1 chase pointer, flag queue is full

{

return FALSE;

}

Q->element[q->rear] = x;

Q->rear = (q->rear + 1)% maxsize;//Reset Team tail pointer

return TRUE;

}


Circle Team List Team

int Deletequeue (seqqueue *q, int *x)//delete queue's team header element, return its value with X

{

if (q->rear = = Q->front)//queue is empty

{

return FALSE;

}

*x=q->element[q->front];

Q->front = (q->front + 1)% maxsize;//Reset team head pointer

return TRUE;

}


This article is from the "Rock Owl" blog, please be sure to keep this source http://yaoyaolx.blog.51cto.com/10732111/1772824

Basic operations such as initialization of cyclic queues, queue-up, team-out, etc.

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.