STL Common Container Summary--queue one-way queue

Source: Internet
Author: User

Original

A one-way queue is similar to a stack where the stack is only adding or removing data at the top of the stack, and a one-way queue adds data from the end of the team and removes the data from the team header. The stack is advanced back-out (FILO), and the one-way queue is FIFO. In the STL, the one-way queue also uses other containers as the underlying data structure, by default using Deque, you can specify vectors and so on.

Queue common functions for one-way queues:

1. Data manipulation

Que.front ()

Returns a reference to the queue header data

Que.back ()

Returns a reference to the tail data of a queue

Que.push (Elem)

Add data at the end of the team

Que.pop ()

Queue head data out team

2. Other operations

Que.empty ()

Determines whether the queue is empty, or returns False if NULL returns TRUE.

Que.size ()

Returns the number of data in the queue


Queue one-way queues example:

#include <iostream>
#include <queue>
#include <vector>
using Std::queue;
Using Std::vector;
int main ()
{
	queue<int> que;//uses deque as the underlying container
	queue<int by default, vector<int> >quev;// Specifies that the vector is the underlying container for
	(int i = 0; i < ++i)
	{
		que.push (i*i);
		Quev.push (i);
	}
	Std::cout << "\ n" Team head Data: "<<que.front ();
	Std::cout << "\ n \ nthe tail data:" << que.back ();
	Std::cout << "\ n Queue Size:" << que.size ();
	Std::cout << "\ n \ nthe data for queue que: \ n";
	while (!que.empty ())
	{
		std::cout << que.front () << "";
		Que.pop ();
	}
	System ("pause");
	return 0;
}



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.