Data structure Practice--queue array

Source: Internet
Author: User

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

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.