Cyclic queue (c)

Source: Internet
Author: User

Cyclic queue (c)

# Include
 
  
Using namespace std; # define MAXSIZE 50 typedef int QueueElementType; typedef struct {QueueElementType elem [MAXSIZE]; int front; // point to the int rear element in the current queue header; // point to the next position of the End Element} SeqQueue; void InitQueue (SeqQueue & Q); void InputQueue (SeqQueue & Q); bool EnterQueue (SeqQueue & Q, QueueElementType x ); queueElementType DeleteQueue (SeqQueue & Q); QueueElementType BackQueue (SeqQueue Q); // return bool IsFull (SeqQueue Q); bool IsEmpty (SeqQueue Q ); void OutputQueue (SeqQueue Q); int QueueLength (SeqQueue Q); int main () {int x; SeqQueue q; InitQueue (q); InputQueue (q ); x = BackQueue (q); cout <"team end element:" <
  
   
> M; while (m! =-1) {if (IsFull (Q) cout <"the current queue is full and cannot be inserted" <
   
    
> M ;}} bool EnterQueue (SeqQueue & Q, QueueElementType x) {if (Q. rear + 1) % MAXSIZE = Q. front) return false; Q. elem [Q. rear] = x; Q. rear = (Q. rear + 1) % MAXSIZE; return true;} QueueElementType DeleteQueue (SeqQueue & Q) {if (IsEmpty (Q) {cout <"the current queue is empty. An error occurred while exiting the queue! "<
    
     

 

Related Article

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.