Data structure on machine 4 queue-Yang Hui Triangle 2

Source: Internet
Author: User

#include <stdio.h>#include<malloc.h>#defineOK 1#defineOVERFLOW-1#defineERROR 0typedefintStatus, Qelemtype;//Queue Structure Definitiontypedefstruct{Qelemtype*Base; intFront; intRear;} Sqqueue;//Initialize QueueStatus Initqueue (Sqqueue *q,intqsize) {Q-Base= (Qelemtype *)malloc(Qsize *sizeof(Qelemtype)); if(! Q->Base)    returnOVERFLOW; Q->front = Q->rear =0; returnOK;}//QueueStatus EnQueue (Sqqueue *q,intqsize, Qelemtype e) {  if((Q->rear +1)% Qsize = = q->front)returnERROR; Q-Base[Q->rear] =e; Q->rear = (Q->rear +1) %qsize; returnOK;}//take the Captain .intGetLength (Sqqueue *q,intqsize) {  return(Q->rear-q->front + qsize)%qsize;}//out TeamStatus DeQueue (Sqqueue *q,intqsize) {  if(Q->front = = q->rear)returnERROR; Q->front = (Q->front +1) %qsize; returnOK;}//show numbers between two and 0Status Print (Sqqueue *q,intqsize) {  //0 1 0//0 1 1 0//0 1 2) 1 0//0 1 3 3 1 0  inti; if(Q->rear = = q->front)returnERROR; printf ("%*c",3* (Qsize-getlength (Q, qsize)),' '); I= (Q->front +1) %qsize;  while((1+ i)% qsize! = q->rear) {printf ("%*d", (i + qsize)/qsize >1? -5:5, q->Base[i]); I= (1+ i)%qsize; } printf ("\ n"); returnOK;}//Yang Hui TrianglevoidYanghuisanjiao (Sqqueue *q,intN) {intqsize; inti; printf ("%d lines of Yang Hui triangle \ n", N); Qsize= n +3;  Initqueue (Q, qsize); EnQueue (Q, Qsize,0); EnQueue (Q, Qsize,1);  for(i =1; I <= N; i++ ) {      while(GetLength (Q, qsize) >2) {EnQueue (q, qsize, q-Base[Q->front] + q->Base[(Q->front +1) %Qsize]);      DeQueue (Q, qsize); if(q->Base[Q->front] = =0)         Break; } EnQueue (Q, Qsize,0);  Print (Q, qsize); }}//Main functionintMainvoid) {    intN;    Sqqueue Q; Puts ("the cyclic queue realizes the calculation of the Yang Hui triangle:"); Puts ("Please enter how many lines? (for observation within recommendation 20)"); scanf ("%d", &N); Yanghuisanjiao (&Q, N); return 0;}

Data structure on machine 4 queue-Yang Hui Triangle 2

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.