Data Structure and Algorithm Analysis Study Notes (5)-team ADT

Source: Internet
Author: User

I. Team Concept

A queue is also a type of table, but it is a type of restricted table. It can only be inserted from one end, and the other end is thick.

Ii. Queue Array Implementation

#define QMAXSIZE 100typedef int Position;typedef int QElement;typedef struct queue{    QElement Els[QMAXSIZE];    Position head,tail;}Queue;void QCreate(Queue &Q){    Q.head = Q.tail = 0;}void Enqueue(QElement e,Queue &Q){    if((Q.tail + 1) % QMAXSIZE == Q.head)    {        printf("Queue Full");    }    else    {        Q.Els[Q.tail] = e;        Q.tail = (Q.tail + 1)% QMAXSIZE;    }}void Dequeue(QElement &e,Queue &Q){    if(Q.head == Q.tail)    {        printf("Queue Empty");    }    else    {        e = Q.Els[Q.head];        Q.head = (Q.head + 1) % QMAXSIZE;    }}QElement Head(Queue Q){    if(Q.tail == Q.head )    {        printf("Queue Empty");    }    else    {        return Q.Els[Q.head];    }}bool Empty(Queue Q){    return(Q.tail == Q.head );}bool Full(Queue Q){    return((Q.tail + 1) % QMAXSIZE == Q.head );}

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.