This article is a practical project for the basic series of data Structure network courses (3): Stacks and queues.
"Project-Queue Array"
Create 10 queues, numbered 0-9 (processed as queue arrays, numbered as subscripts). Enter several positive integers, ending with a number of 0. Set the input value to x, and its single digit size is I, then insert X into the queue numbered I. Finally, all non-empty queues are output.
The queue is required to be processed into a chained queue, using the data types and algorithms defined in the chain Queue algorithm Library, and only one function (main function) is included in the program, and the queued and outbound operations are called directly in the main function.
Set Program Runtime input: 70 59 90 72 67 88 80 64 29 97 18 83 40 13 0
Output results such as:
Tips:
-pointers to individual chains are defined as follows:
LiQueue *qu;
-the array of queues used in this project actually needs to store the pointers of the 10 chain teams sequentially into an array, as defined below:
LiQueue *qu[10]; //qu是数组,数组中存储指针,存储的是指向LiQueue类型的指针
[Reference Solution] (The Chain Queue algorithm Library (liqueue.h) used in this article, please click the link ...)
#include <stdio.h>#include <malloc.h>#include "liqueue.h"#define NintMain () {intI, A; Liqueue *qu[n];//define array of queue pointers for(i=0; i<n; i++) Initqueue (Qu[i]);//Initialize queue //Add a value to the queue printf("Enter a number of positive integers ending with 0:");scanf("%d", &a); while(a) {EnQueue (qu[a%Ten], a);scanf("%d", &a); }//Output each queue printf("by single-digit sorting into each queue, teams are listed as the result: \ n"); for(i=0; i<n; i++) {printf("qu[%d]:"+ N); while(! Queueempty (Qu[i])) {DeQueue (Qu[i], a);printf("%d", a); }printf("\ n"); }//Destroy individual queues for(i=0; i<n; i++) Destroyqueue (Qu[i]);return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Data structure Practice--queue array