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