0 ratings0% found this document useful (0 votes) 24 views6 pagesData Structures Cheat Sheet
Cheat sheet of important data structures
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
‘12424, 1:56 AM
Cheatsheets / C++ for Programmers
C++'s Built-In Data
vectors
In C+4,a vector isa data structure that stores a sequence
of elements that can be accested by index.
Unlike arrays, vectors can dynamically shrink and grow in
‘The standard
‘extracted only from one end of the container.
+ push) add an element atthe top of the stack
+ .pop() remove the element atthe top of the
stack
Queues are designed to operate ina Fist-In-First-Out
context (FIFO), where elements are inserted into one end
‘of the container and extracted from the other.
+ .push() add an element at the end of the queue, RP
+ -pop() remove the element atthe front ofthe
queue.
f empty
push (10) ;
push (9
push (8
front () <<" ";
hitps:www-codecademy,comilearne-pls-plisfor-programmersimodulesicpp-bull-in-date-stucturesicheatshest 26‘12424, 1:58 AM
Sets
In C++, a sets a data structure that contains a collection
‘of unique elements. Elements of a set are index by thelr
‘own values, oF keys
set cannot contain duplicate elements. Once an
‘element has been added to a set, that element cannot be
modified.
‘The following methods apply to both unordered_set
and set
+ insert() : add an element to the set
+ .erase() : removes an element from the set
+ -count() : check whether an element exists in the
+ -size() sreturn the size ofthe set.
htips:siww-codecasemy comileare:plus-plus-for-programmersimoduleslepp-bl-n-data-stucturesicheatshest
“[eodelcademy
nsert (11)
not inse
erase (2);
erase (13);
// Outputs: primes does not contain 2.
contains 2.\n";
mes does not contain
316‘2024, 1:56 AM
arrays
Arrays in C++ are used to stare a collection of values of 1
the same type. The size of an array is specified when itis
declared and cannot change afterward,
Use [] and an integer index to access an array element, ng nanesr 3
Keep in mind: array indices start with O, not 1 1
‘A multidimensional array Is an “array of arrays" and is.
declared by adding extra sets of indices to the array
Outputs:
har 3113
outputs:
hitps:www-codecademy,comilearne-pls-plisfor-programmersimodulesicpp-bull-in-date-stucturesicheatshest 416‘12424, 1:58 AM
Hash Maps
In C+4, a hash map is a data structure that contains a
collection of unique elements in the form of key-value
Pairs. Elements of a hash map are identified by key values,
while the mapped values are the content associated with
the keys.
Each element of a map or unordered_map is an
object of type pair .A pair object has two member
variables:
+ first isthe value of the key
+ second is the mapped value
‘The following methods apply to both unordered_map
and map
+ insert() : add an element to the map.
+ .crase() : removes an element from the map.
+ .count() : check whether an element exists in the
map,
+ -size() return the size of the map.
+ [] operater:
© lithe specified key matches an element in
the map, then access the mapped value
associated with that key.
© Ifthe specified key doesn't match any
element in the map, add a new element to
the map with that key.
“[eodelcademy
"Japan"} = 81; uw
a new element
Thailand") = 66; //
Access an element
// Outputs: There isn't a code for
Belgium
elgium")}
<< "There is a code f
i“
“
utputs: Japan 81
https sww-codecasemy comileare:plus-plus-for-programmersimoduleslepp-bll-n-data-stucuresicheatshest 56/ thailand 66 [eodelcademy
ee "\n";
cb Print 8 Share v
hitps:www-codecademy,comilearne-pls-plisfor-programmersimodulesicpp-bull-in-date-stucturesicheatshest ars