C++ Data Structures: Vectors and the STL

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/44

flashcard set

Earn XP

Description and Tags

Flashcards for reviewing C++ data structures, vectors, and the STL.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

45 Terms

1
New cards

Data Structure Definition

A way of organizing and storing data in a computer so that it can be used efficiently.

2
New cards

Three Main Goals of Data Structures

Storage, Access, Manipulation.

3
New cards

Linear Data Structure

Elements are arranged in a sequential order.

4
New cards

Examples of Linear Data Structures

Arrays, Linked Lists, Stacks, Queues

5
New cards

Non-Linear Data Structures

Elements are not arranged sequentially, often using a hierarchy.

6
New cards

Examples of Non-Linear Data Structures

Trees, Graphs

7
New cards

Why Data Structures Matter

Saves time and resources by providing optimized methods for data operations; simplifies complex problems by organizing data in a logical way; enables programs to handle growing amounts of data effectively.

8
New cards

The C++ Standard Template Library (STL)

A collection of pre-built, generic classes and functions that implement common data structures and algorithms.

9
New cards

Key Components of the STL

Containers, Iterators, Algorithms

10
New cards

Containers (STL)

Objects that store data (e.g., vectors, lists, maps).

11
New cards

Iterators (STL)

Used to traverse elements within a container. They act like pointers, enabling you to move through the data.

12
New cards

Algorithms (STL)

Functions that perform operations on containers (e.g., sorting, searching).

13
New cards

What is a Vector?

A dynamic array that can change its size as needed during program execution.

14
New cards

Header File for Vectors in C++

15
New cards

Syntax for Creating a Vector

vector vectorName;

16
New cards

Methods for Accessing Vector Elements

[], .at(), .front(), .back(), .size()

17
New cards

.assign() (Vector Operation)

Fill a vector with new values.

18
New cards

.push_back() (Vector Operation)

Adds an element to the end of the vector.

19
New cards

.pop_back() (Vector Operation)

Removes the last element of the vector.

20
New cards

.insert() (Vector Operation)

Inserts elements at a specific position in the vector.

21
New cards

.clear() (Vector Operation)

Removes all elements from the vector.

22
New cards

.erase() (Vector Operation)

Removes elements at a specific position or range in the vector.

23
New cards

.empty() (Vector Operation)

Checks if the vector is empty (returns true if empty, false otherwise).

24
New cards

.resize() (Vector Operation)

Changes the size of the vector.

25
New cards

.rbegin() & .rend() (Vector Operation)

Reverse iterators for traversing the vector in reverse order.

26
New cards

.swap() (Vector Operation)

Swaps the contents of two vectors.

27
New cards

Ways to Access Vectors Using Loops

Using index-based for loop and range-based for loop (C++11 and later).

28
New cards

Iterator Definition

A special type of pointer that allows you to traverse the elements of a container without directly manipulating memory addresses.

29
New cards

Common Iterator Methods

.begin(), .end(), .rbegin(), .rend()

30
New cards

Different Types of Iterators

Input Iterators, Output Iterators, Forward Iterators, Bidirectional Iterators, Random Access Iterators

31
New cards

Dereferencing (*) (Iterator Operation)

Access the value the iterator points to.

32
New cards

Incrementing (++) (Iterator Operation)

Move to the next element.

33
New cards

Decrementing (--) (Iterator Operation)

Move to the previous element (bidirectional iterators).

34
New cards

Algorithms Definition (STL)

Generic functions in the STL that operate on ranges of elements within containers.

35
New cards

Header to Include for STL Algorithms

36
New cards

Common STL Algorithms

sort(), find(), copy(), transform(), count(), remove()

37
New cards

Linear Data Structures Definition

Store elements in a sequential or ordered manner.

38
New cards

Non-Linear Data Structures Definition

Do not store elements in a sequential order; elements are often organized in a hierarchical or networked manner.

39
New cards

.capacity() (Vector Operation)

Returns the number of elements the vector can hold without reallocating memory.

40
New cards

.reserve() (Vector Operation)

Requests that the vector allocate a specific amount of memory.

41
New cards

.shrinktofit() (Vector Operation)

Requests that the vector reduce its capacity to match its size.

42
New cards

.emplace_back() (Vector Operation)

Constructs an element in-place at the end of the vector.

43
New cards

.emplace() (Vector Operation)

Constructs an element in-place at a specified position in the vector.

44
New cards

.find() (Vector Operation)

Locates elements in a range.

45
New cards

std::distance() Definition

Calculates the distance between two iterators.