Dual-ended queues

Source: Internet
Author: User

1#include <iostream>2#include <cstring>3 using namespacestd;4 #defineSize 105 structSqueue6 {7     intQueue[size];8     intfront,rear;9 };Ten voidInitqueue (Squeue *sq) One { ASq->front=sq->rear=0; - } - intIsEmpty (Squeue *sq) the { -     if(sq->front==sq->rear) -         return 1; -     return 0;  + } - intEnqueue (Squeue *sq,intEintde) + { A  at     if(de==0) -     { -         if(sq->front==0) -         { -             return 0; -         } in         Else -         { tosq->front--; +sq->queue[sq->front]=e; -         } the     } *     Else $     {Panax Notoginseng         if(sq->rear==size) -         { the             return 0; +         } A         Else the         { +sq->queue[sq->rear]=e; -sq->rear++; $         } $     } - } - intOuqueue (Squeue *sq,int&e,intde) the { -     if(IsEmpty (sq))Wuyi         return 0; the     if(de==0) -     { WuE=sq->queue[sq->Front]; -sq->front++; About     } $     Else -     { -e=sq->queue[sq->rear-1]; -sq->rear--; A     } + } the intMainintargcChar Const*argv[]) - { $ squeue S; theInitqueue (&s); the     inti,e; the      for(i=0;i<5; i++) theEnqueue (&s,i,1); -      for(i=0;i<5; i++) in     { theOuqueue (&s,e,0); thecout<<e<<' '; About          the     } thecout<<Endl; the      for(i=Ten; i>=6; i--) +     { -Enqueue (&s,i,0); the     }Bayi      for(i=0;i<5; i++) the     { theOuqueue (&s,e,1); -cout<<e<<' '; -     } the     return 0; the}

Dual-ended queues

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.