ankushbhardwxj / codemon

cli to win programming contests
https://pypi.org/project/codemon/
MIT License
26 stars 12 forks source link

s #9

Closed ankushbhardwxj closed 4 years ago

ankushbhardwxj commented 4 years ago

Contents :

Member functions

Iterators

Capacity

Vector STL container

These are arrays that can change in size. They are contiguous storage locations for their elements, which means that their elements can be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays. However, size can change dynamically, with their storage being handled automatically by the container. Vectors use array that may need to be dynamically reallocated to grow in size when new elements are inserted, which implies allocating a new array and moving all elements to it. Compared to arrays, vectors consume more memory to manage storage dynamically. The properties of this container are - Sequence, Dynamic arrays and allocator aware.

Member functions

Iterators:

Capacity:

Modifiers:

Note: We can also assign a vector to another vector as follows:

vector<int> a = {1,2,3};
vector<int> b;
b = a;

Deque STL container

Deque (double-ended queue) are sequence containers with dynamic sizes that can be expanded or contracted on both ends. They provide functionality similar to vectors but with efficient insertion and deletion of elements also at beginning , and not only to end. Both vectors and deques provide similar functionality, but they work in different ways: vectors use a single array that is reallocated for growth, the elements of a deque can be scattered in different chunks of storage, with the container keeping the necessary information internally to provide direct access to any of its elements in constant time and with uniform sequential interface. Note :- For operations that involve frequent insertion or removals of elements at positions other than the beginning or end, deques perform worse and have less consistent iterators than lists and forward lists

Member Functions :

Iterators :

begin, end, rbegin, rend

Capacity :

size, max_size, resize, empty, shrink_to_fit

Element access :

[], at, front, back

Modifiers :

assign, push_back, push_front, pop_back, pop_front, insert, erase, swap, clear.

deque<int> a(n) = {1,2,3,4};
a.push_front(0); // 0,1,2,3,4
a.push_back(5); // 0,1,2,3,4,5
while(!a.empty()){
  a.pop_front();
  a.pop_back();
}
/*
Popping occured as follows : 
0 1 2 3 4 5 
1 2 3 4
2 3
NULL
*/

List STL container

Lists are sequence containers that allow constant time insert and erase operations anywhere within the sequence, and iteration in both directions. Lists are basically doubly-linked lists. The difference between list and forward_list is that forward_list objects are single linked lists and can only be iterated forwards. Compared to other sequence containers, lists perform better in inserting, extracting and moving elements in any position within the container. The major drawback of list and forward_lists is that they lack direct access to the elements by their position. They also consume some extra memory to keep the linking information associated to each element.

Member Functions

Iterators:

begin, end, rbegin, rend

Capacity:

empty, size, max_size

Element access:

a.remove_if(is_odd());

- `unique`: this function without parameters removes all but the fitst element from every consecutive group of equals in the container. Notice that an element is only removed from the list container if it compares equal to the element immediately preceding it. Thus, this function is especially useful for sorted lists. 
The function accepts a single argument which is a predicate or condition on which uniqueness is judged.
```cpp
a.unique();

Set STL container

Sets are containers that store unique elements in a specific order. Each value in the set should be unique. They can be inserted and removed but cannot be modified. Sets are typically implemented as binary search trees.

Member functions :

Iterators:

begin, end, rbegin, rend

Capacity:

empty, size, max_size

Modifiers :

insert: extends the container by inserting new elements, returns a pair where pair::first points to either the newly inserted element is already in set. The pair::second element in the pair is set to true if a new element was inserted or false if equivalent element already exists.

set<int> a; 
a.insert(x);

Operations :

Multi-Set STL container

Multisets are containers that store elements following a specific order and where multiple elements can have equivalent values. In multiset, elements can be added or removed but cannot be modified. They are similar to javascript objects, and exist as key value pairs.

multiset<int> a;

Member function

Iterators:

begin, end, rbegin, rend

Capacity:

empty, size, max_size

Modifiers:

insert, erase, swap, clear

Observers:

key_comp, value_comp

Operations:

find, count, lower_bound, upper_bound, equal_range Note : All functions are similar to that of set

Map STL container

Maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order. Maps are implemented as binary search trees. In a map, the key values are generally used to sort and uniquely identify the elements, while the mapped values store the content associated with the key. The types of key and mapped value may differ. The mapped values in a map can be accessed directly by their corresponding key using the bracket operator.

Member functions:

Iterators :

begin, end, rbegin, rend

Capacity :

empty, size, max_size

Element access :

Observers

key_comp, value_comp

Operations

find, count, lower_bound, upper_bound, equal_range

Multimap STL container

These are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order, and where multiple elements can have equivalent keys. In a multimap, the key values are generally used to sort and uniquely identify the elements, while the mapped values store the content associated to this key. The types of key and mapped value may differ. They are generally implemented as binary search trees.

multimap<char, int> a;

Member function

Iterators

begin, end, rbegin, rend

Capacity

empty, size, max_size

Modifiers

insert, erase, swap, clear

Observers

key_comp, value_comp

Operations

find, count, lower_bound, upper_bound, equal_range