Algorithm notes - STL and frequently asked questions

vectorvector<typename> namefunctionfunctionTime complexitypush_back(x)Add an element after the vectorO(1)pop_back()Delete the tail element of the vectorO(1)size()Get the number of elements of the vectorO(1)clear()Empty all elements in the vectorO(N), N is the number of vector elementsinsert(it,x)Insert an element x into any iterator it of ...

Posted on Mon, 06 Dec 2021 01:01:34 -0500 by fiorefrank

C + + Hou Jie STL standard library and Generic Programming Notes

C++STL This blog post refers to Mr. Hou Jie's STL generic programming course and records the more important parts for future review. I highly recommend Mr. Hou Jie's C + + series. It really exists like the Bible! 1.STL six components Containers Allocators Algorithms Iterators Adapters Functors 2. Distributor allocator completes al ...

Posted on Mon, 29 Nov 2021 14:43:18 -0500 by peppino

Experience in stl use -- ensure that less < T > and operator < have the same semantics

As we all know, the stl container has a default sorting function. The default sorting less < T > is generally sorted by size. If we store custom elements and assume that we have multiple sorting factors, it mainly depends on how the operator < function in our custom class is written. Let's start with an example. #include <iostream ...

Posted on Sun, 28 Nov 2021 16:20:34 -0500 by brian79

Detailed explanation of STL associated container

STL associative container category 1. map Defined in the header file, the key of each element of the data stored in this container must be unique (that is, it cannot be repeated). The container will sort in ascending order by default according to the size of the key of each element (call std::less). 2. set Defined in the header file, using t ...

Posted on Fri, 26 Nov 2021 04:03:40 -0500 by HIV

The use of [C/C++ -STL]list and the failure of vector and list iterators

1, List introduction What is a list template < class T, class Alloc = allocator<T> > class list; This is the definition given in the document So what is a List? List is a sequence container that allows fixed time insertion and erasure operations to be performed anywhere in the sequence, and iterates in two directions. They are s ...

Posted on Tue, 23 Nov 2021 05:06:22 -0500 by wendu

[C/C++] Detailed introduction of STL container 4--AVL tree and partial simulation implementation

This paper introduces AVL tree and simulates its core functions. Catalog 1. The concept of AVL tree   2. Definition of AVL tree node 3. Insertion of AVL Tree 4. Rotation of AVL Trees 1. The new node is inserted to the left of the higher left subtree - left left: right single-handed 2. Insert the new node to the right of the higher r ...

Posted on Sun, 21 Nov 2021 16:40:12 -0500 by tina88

[STL source code analysis] summary notes: clever deque

00 in front [STL source code analysis] summary note (6): the design of iterator and magical traits After mastering the basic design principles of iterators, we can look at the implementation of the remaining sequential containers. At this time, we can focus more on the design of each container itself. 01 overview deque is a continuous line ...

Posted on Tue, 09 Nov 2021 16:19:20 -0500 by jscruggs

Some basic usage of STL commonly used in C + +

C++STL 1. vector Description: variable length array with multiplication idea Function: size(): returns the number of elements (almost all containers have)empty(): Returns whether it is empty (almost all containers have)clear(): clearfront()/back(): returns the first / last element in the vectorpush_back()/pop_back(): insert an element af ...

Posted on Sun, 31 Oct 2021 17:52:04 -0400 by brbsta

Stack and queue exercises

Stack: first in, last out, use of STL standard stack: #include < stack > Queue: last in and last out --#include < queue > Stack basic functions: push(x); Stack pressing pop(); Pop stack, do not return any value top(); Returns the element at the top of the stack empty(); Return true/false to judge whether the stack is empty U ...

Posted on Wed, 13 Oct 2021 07:56:13 -0400 by adrian_melange

Introduction to C + + - Speech Contest process management system

Reference link https://www.bilibili.com/video/BV1et411b73Z?p=264 Speech contest process management system Program requirements of speech contest Competition rules The school held a speech contest, in which 12 people participated. There are two rounds in the competition. The first round is the knockout and the second round is the finalEach ...

Posted on Sun, 19 Sep 2021 04:12:07 -0400 by crazydip