Queue Learning Summary

Source: Internet
Author: User

The rule is this: first delete the 1th number, and then put the 2nd number at the end of the string, then delete the 3rd number and then the 4th number to the end of the string, and then delete the number of 5th ... Until the last number is left, the last number is also deleted. In the order that you just removed, the number of these deletions is the number of requests, and the number of strings is "6 3 1  the 8 9 2 4"Output 61 5 9 4 7 2 8 3. #include<stdio.h>intMain () {intq[102]={0,6,3,1,7,5,8,9,2,4},head,tail; inti; //Initialize QueueHead=1; Tail=Ten;//There are already 9 elements in the queue, the last position of the tail's tail     while(Head<tail)//Loop is executed when the queue is not empty    {        //Print the team first and the team first out of the teamprintf"%d", Q[head]); Head++; //first add the first number of new team to the end of the teamq[tail]=Q[head]; Tail++; //and the team's first team .head++; }           return 0;} The queue will be our future learning breadth-first search and queue optimization Bellman-The core data structure of the Ford shortest path algorithm. So now the three basic elements of the queue (an array, two variables) are encapsulated as a struct type, as follows # #<stdio.h>structqueue{intdata[ -];//the body of the queue, used to store the content    intHead//Team First    intTail//End of Team};intMain () {structqueue q; inti; //Initialize QueueQ.head=1; Q.tail=1;  for(i=1; i<=9; i++)    {        //Insert 9 numbers into a queue in turnscanf"%d",&Q.data[q.tail]); Q.tail++; }        while(Q.head<q.tail)//Loop is executed when the queue is not empty    {        //Print the team first and the team first out of the teamprintf"%d", Q.data[q.head]); Q.head++; //first add the first number of new team to the end of the teamq.data[q.tail]=Q.data[q.head]; Q.tail++; //and the team's first team .q.head++; }         return 0;}

Queue Learning Summary

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.