-
Notifications
You must be signed in to change notification settings - Fork 43
Module 4 : STL Containers
Container is an object that is used to store a collection of other objects (called elements in the container) and manage their storage space. In C ++, container is implemented as a template class, so that there are functions to access its elements.
Do you still remember Array?
std::array is a type of data structure that holds elements sequentially with a fixed size (fixed-size).
Operations on std::array:
-
operator []- Accesses the element at a specific position. -
at()- Accesses the element at a specific position while checking the array size limit. Returns the same value asoperator []''. The difference is when the index of the element to be accessed exceeds the array size limit. On `at (),` the program will throw an `out_of_range` error when running. On theoperator []``, this causes an undefined behavior. -
front()- Accesses the first position element. -
back()- Accesses the element in the last position. -
begin()- An iterator for the start of the sequence. -
end()- An iterator for the element after the end of the sequence. -
size()- Get the number of elements. -
max_size()- Get the maximum number of elements the array can hold. Returns the same value assize (). -
empty()- Checks whether the array is empty or not. If array size is 0, returns true. Otherwise, returns the valuefalse. -
swap()- Swaps all elements in an array with all elements in another array that have the same data type and size. -
fill()- Fills all the elements in the array with a specific value.
Do you still remember [Dynamic Array] (https://github.com/AlproITS/StrukturData/wiki/Modul-0-(Dynamic-Array))?
std::vector is a type of data structure that represents an array with the ability to change size (capacity) dynamically according to the amount of data entered.
Operations on std::vector:
-
operator[]- Accesses the element at a specific position. -
at()- Accesses element in specific position while checking vector size limit. Returns the same value as theoperator []. The difference is when the index of the element to be accessed exceeds the vector size limit. Onat (),the program will throw anout_of_rangeerror when running. On theoperator[], this causes an undefined behavior. -
front()- Accesses the first position element. -
back()- Accesses the element in the last position. -
begin()- An iterator for the start of the sequence. -
end()- An iterator for the element after the end of the sequence. -
size()- Get the number of elements. -
max_size()- Get the maximum number of elements the vector can hold. -
resize()- Resizes a vector to a specified number of elements.resize ()can also be accompanied by specifying a specific value, but it will not change an element that has a previous value (as opposed toassign ()). -
empty()- Checks whether the vector is empty or not. If the vector size is 0, returns true. Otherwise, returns the valuefalse. -
assign()- Set the vector size to be a certain number of elements with a certain value on all elements. -
push_back()- Adds the element at the last position. -
pop_back()- Deletes the last element. -
insert()- Inserts a value at a specific position (or range). -
erase()- Deletes the value at a specific position (or range). -
clear()- Removes all elements, so the vector size is 0. -
swap()- Swaps all elements in a vector with all elements in another vector that have the same data type (size can be different). -
sort(first, last)- Sorts the elements in the array by descending in the range (first, last). -
lower_bound(first, last, val)- Returns an iterator that points to the smallest element not less than $ val $ in the range (first, last). If it doesn't exist, it returns the last iterator. -
upper_bound(first, last, val)- Returns an iterator that points to the smallest element that is more than $ val $ in the range (first, last). If it doesn't exist, it returns the last iterator.
Modul Struktur Data
Ditulis oleh tim Asisten Struktur Data 2020 - Teknik Informatika ITS
Modul 0
- Pengenalan Struktur Data IND | ENG
- Dynamic Array IND | ENG
- Linked List IND | ENG
- Soal Latihan IND | ENG
Modul 1
- Stack IND | ENG
- Queue IND | ENG
- Deque IND | ENG
- Priority Queue (List Based) IND | ENG
- Soal Latihan IND | ENG
Modul 2
- Pengenalan Tree IND | ENG
- Binary Search Tree IND | ENG
- Traversal BST IND | ENG
- Soal Latihan IND | ENG
Modul 3
Modul 4
- Melangkah Menuju C++ | ENG
- Standard Template Library Container | ENG
- Pengenalan Graf | ENG
- Traversal Graf | ENG
Modul 5