C++ PS 관련 정리

천호영·2024년 1월 22일
0

알고리즘

목록 보기
94/100

STL

STL Vector

The vector container provides a dynamic arrray. It is defined as std::vector class template inside header file.

  • Vector Declaration
#include <vector>

vector <data_type> vector_namx; // 1D vector
vector < vector<data_type> > vector_name; // 2D vector
  • std::vector Member Functions
  1. begin(): Returns an iterator to the first element. O(1)
  2. end(): Returns an iterator to the theretical element after the last element. O(1)
  3. size(): Returns the number of elements present. O(1)
  4. empty(): Returns true if the vector is empty, false otherwise. O(1)
  5. at(): Returns the element at a particular position. O(1)
  6. assign(): Assign a new value to the vector elements. O(N)
  7. push_back(): Adds an element to the back of the vector. O(1)
  8. pop_back(): Removes an element from the end. O(1)
  9. insert(): Insert an element at the specified position. O(N)
  10. erase(): Delete the elements at a specified position or range. O(N)
  11. clear(): Removes all elements. O(N)

STL List

The list container implements the doubly linked list data structure. It is defined as std::list inside header file.

  • List Declaration
#include <list>

list <data_type> list_name;
  • std::List Member Functions
  1. begin(): Returns iterator to the first element. O(1)

STL Deque

The deque implements the double-ended queue which follows the FIFO mode of operation but unlike the queue. the deque can grow and shrink from both ends. It is defined as std::deque inside header file.

  • Deque Declaration
#include<deque>

deque <data_type> deque_name;

STL Stack

The Stack is a container adaptor that operates one LIFO principle. It is defined as std::stack in header file.

  • Stack Declaration
#include<stack>

stack <data_type> stack_name;

STL Queue

The Queue is a container adapter that uses the FIFO mode of operation where the most recently inserted element can be accessed at last. It is defined as the std::queue class template in the header file.

  • Queue Declaration
#include <queue>
queue <data_type> queue_name;

STL Set

STL Map

STL Unordered_set

STL Unordered_map

STL Algorithms

Reference

C++ STL Cheat Sheet

profile
성장!

0개의 댓글