List Headline Image
Updated by Santosh Sahu on Aug 15, 2020
 REPORT
Santosh Sahu Santosh Sahu
Owner
9 items   1 followers   9 votes   2 views

C++ Tutorial

C++ is a middle-level and general-purpose programming language created by Bjarne Stroustrup starting in 1979 at Bell Labs. It is an extension to C programming with additional implementation of object-oriented programming (OOPS) concepts. It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. C++ is the most widely used programming languages in application and system programming.

This tutorial is intended for students or professionals interested in studying basic and advanced concepts of C++. This tutorial covers all topics of C++ which includes data types, operators, arrays, strings, control statements, pointers, classes, object-oriented programming, constructor, destructor, inheritance, polymorphism, encapsulation, namespace, exception handling & File IO.

Source: https://www.alphacodingskills.com/cpp/cpp-tutorial.php

A vector is a sequence container implementing array that can change in size. Unlike array, the size of a vector changes automatically when elements are appended or deleted.

Vector stores elements in contiguous memory location which enables direct access of any elements using operator []. To support shrink and expand functionality at runtime, vector container may allocate some extra storage. Hence, compared to array, vector requires more memory and in return it manage memory dynamically and efficiently.

A forward list is a sequence container that stores data of same type. List container is implemented as singly-linked lists, hence provides sequential access of its data. It also allow constant time insertion and deletion operations anywhere within the sequence. Please note that, forward_list can only be iterated forwards.

The forward_list supports shrink and expand functionality at runtime, hence, list requires more memory and in return it manage memory dynamically and efficiently.

The main disadvantage of using list and forward_list as compared to other sequence container is that they lack direct access of any elements by its position, for example - using operator []. To access any element in a forward_list, iteration need to be done from a known position (like beginning or end of the list) to the element's position, which takes linear time to access element.

A queue is a linear dynamic data structure that follows First-In/First-Out (FIFO) principle. In a queue, addition of a new element and deletion of an element occurs at different end which implies that the element which is added first in the queue will be the first to be removed from the queue.

Features of queue

  • It is a dynamic data structure.
  • It has dynamic size.
  • It uses dynamic memory allocation.

A stack is a linear dynamic data structure that follows Last-In/First-Out (LIFO) principle. In a stack, addition of a new element and deletion of an element occurs at the same end which implies that the element which is added last in the stack will be the first to be removed from the stack.

Features of stack

  • It is a dynamic data structure.
  • It has dynamic size.
  • It uses dynamic memory allocation.

An array is a sequence container that stores specific number of elements of same data type. Unlike vector, the size of an array is fixed. It stores data strictly in linear sequence.

Array stores elements in contiguous memory location which enables direct access of any elements using operator []. It uses implicit constructor to allocate required memory statically at compile time, hence its size cannot shrink or expand at runtime.

A map is an associative container that stores data sequence in key-value pair which is sorted by key. In a map, no two mapped values can have the same key. The data type of key and mapped value may differ and can be represented as:

typedef pair value_type;

Each key in a map is unique which can be inserted or deleted in the map but can not be altered. Values associated with keys can be changed. The value in a map can be directly accessed by specifying corresponding key using the operator [].

A set is an assosiative container that stores unique sorted elements. In a set, the value of the element is itself the key, of type T. Each value in a set is unique which can be inserted or deleted in the set but can not be altered.

Sets are typically implemented as Binary Search Tree.

template < class T, // key_type/value_type
class Compare = less, // key_compare/value_compare
class Alloc = allocator> // allocator_type
> class set;

A priority queue is a dynamic data structure that holds priority. It is similar to a heap, where elements can be inserted in any order and max heap element is retrieved first. Similarly, max heap element is deleted first.

Features of queue

  • It is a dynamic data structure.
  • It has dynamic size.
  • It uses dynamic memory allocation.

Deque stands for Double Ended Queue. A deque is a sequence container with dynamic size and it can be expanded or contracted from both sides (front side or back side). The size of a deque changes automatically when elements are appended or deleted. Along with this, it stores elements of same data types and strictly in linear sequence.

Unlike vector, a deque is not guaranteed to store elements in contiguous memory location, hence it does not support direct access of data by offsetting pointers. But it enables direct access of any elements using operator []. Deque provides similar functionality as vector, but provides efficient way to insert or delete data from any end.