Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Queue queue template in C++

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of Queue queue template in C++. What is introduced in this article is very detailed and has certain reference value. Interested friends must finish it!

1. Introduction of the queue

Definition of queues

Queue (Queue) is a linear storage structure. It has the following characteristics:

Enter and leave the queue according to the "FIFO, First-In-First-Out" mode.

The queue only allows the take-out operation (out of the queue) at the "head of the queue" and the insert operation (enter the queue) at the end of the queue.

Queues can be implemented in two ways

Implementation based on dynamic array

Implementation based on linked list

Functions that need to be implemented in the queue

T dequeue (): leaves the queue and returns the fetched element

Void enqueue (const T & t): join the queue

T & head (): get the team leader data, but will not be taken out

Const T & head () const: get team head data of const type

Int length () const: get the quantity (the parent class has been implemented)

Void clear (): clear the queue (the parent class has been implemented)

two。 Code implementation

In this chapter, the queue we implemented is based on a linked list, and its parent class is the LinkedList class that we implemented earlier:

Detailed explanation of C++ two-way circular chain list template example

So the Queue.h code is as follows:

# ifndef QUEUE_H#define QUEUE_H#include "throw.h" / / throw.h defines a macro for ThrowException to throw an exception, as follows: / / # include / / using namespace std;//#define ThrowException (errMsg) {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report