Data structure Practice project--queue

Source: Internet
Author: User

This group of projects addresses 7-12 lessons in the basic series of data Structures (3): Linear table:

7. Definition of a queue
8. Storage and basic operation of sequential teams
9. Storage and basic operation of ring queue
10. Queue chain storage structure and implementation of basic operation
11. Queue Application-Maze problem
12. Double-ended queue

"Project 1-Establish sequential ring queue algorithm Library"
Define the sequential ring queue storage structure, implement its basic operations, and complete the test.
Requirements:
1. The header file sqqueue.h defines the data structure and declares the function used to complete the basic operation. Functions that correspond to basic operations include:

void InitQueue(SqQueue *&q);  //初始化顺序环形队列void//销毁顺序环形队列bool QueueEmpty(SqQueue *q);  //判断顺序环形队列是否为空int QueueLength(SqQueue *q);   //返回队列中元素个数,也称队列长度bool enQueue(SqQueue *&q,ElemType e);   //进队bool deQueue(SqQueue *&q,ElemType &e);  //出队

2. Implement these functions in Sqqueue.cpp
3. Complete the test in the main function, including the following:

(1) Initialize queue Q
(2) sequentially into the queue element a,b,c
(3) Determine if the queue is empty
(4) An element of the team
(5) Number of elements in the output queue
(6) sequentially into the queue element d,e,f
(7) Number of elements in the output queue
(8) Delete all the elements in the queue and output the sequence
(9) Release queue

[Reference Solution]

"Project 2-Build the chain algorithm library"
Define the chain storage structure, implement its basic operations, and complete the test.
The specific requirements refer to item 1.
[Reference Solution]

"Project 3-negative numbers drive positive numbers out of the queue"
Set from the keyboard input an integer sequence a1,a2,...an, the pilot program implementation: When Ai>0, Ai into the team, when Ai<0, will be the team first element out of the team, when the ai=0, indicating the input end. The queue is required to be processed into a ring queue, using the data types and algorithms defined in the Ring Queue algorithm library, only one function (main function) is included in the program, and the queued and outbound operations are called directly in the main function. Print an error message when the team is out of line (e.g. team full).
[Reference Solution]

"Item 4-Array of queues"
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:
A pointer to a single chain is 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]

"Item 5-queuing for a doctor simulation"
Write a procedure that reflects a patient's visit to a hospital and a queue to see a doctor. There are two main things to repeat during the patient queue:
(1) The patient arrives at the clinic, gives the medical records to the nurse, waits in the waiting queue.
(2) The nurse takes the next patient's medical record from the waiting queue and the patient enters the clinic.
The process of simulating patient waiting for a doctor is required. The program adopts the menu method, and its options and functions are described as follows:
(1) Queue-Enter the patient's medical record number and join the patient queue.
(2) The patient is in line with the first patient in the queue and removes it from the queue.
(3) Check queue-List all the patient's medical record numbers from the first team to the end of the queue.
(4) no longer in line, the remaining sequence of visits-from the first team to the end of the queue to list all the patient's medical record number, and quit running.
(5) off-duty-quit running, suggesting that the patient will come again tomorrow.
The results of the operation can be as follows:
  

[Reference Solution]

"Project 6-Parking Simulation"
The parking lot is a narrow cul-de-sac that can park n cars, the southern seal, and cars only from the north (such parking lots are rare in the world). Cars in the parking lot according to the arrival time of the vehicle, the first car arrived at the southernmost end of the yard, in turn north row. If the car is already full of n cars, then the cars can only wait on the waiting room outside the door, and once the car has left, the first car on the waiting ground will be opened. When a car in the car park is leaving, the vehicle that enters after it must exit the car park to make way for it (assuming that the car has a sidewalk for vehicular access, all drivers must be in the vehicle at any time), and the other vehicles will enter the depot in the original order when the vehicle is out. Every car parked in the yard will be charged for the duration of the stay when it leaves the parking lot. Try to prepare the simulation program for the parking lot management according to the above requirements.

  

Tips:
Simulation of parking in the stack, to the queue to simulate the waiting area outside the yard, when the car left, for the vehicle in and out of the sidewalk should also be represented by the stack. Simulation management is performed according to the input data sequence read from the keyboard. When the car arrives and leaves, each group of input data includes the car license number (set as an integer) and the time of arrival or departure (for simplification, also set to Integer, such as 1, on behalf of the car park to open the 1th hour). The output information for each set of input data is as follows: If the vehicle arrives, it will output the parking position of the car in the parking lot or the garage, and if the vehicle is left, the time of the car's stay in the parking lot and the fee payable (no charge for the time of stay on the waiting room). The stack is implemented in a sequential structure, and the queue is implemented in a linked list structure.

[Reference Solution]

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Data structure Practice project--queue

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.