Skip to content

Latest commit

 

History

History
105 lines (66 loc) · 4.27 KB

File metadata and controls

105 lines (66 loc) · 4.27 KB

C++ Programming Patterns

These modern C++ examples are meant to serve as examples for me to reference now that I've determined to stop programming in C++ as if it were C. The STL, now that I'm using it regularly is so great that I hardly feel stripped of my Python powers. Well... list comprehensions... I mostly miss that.

Random Numbers

  1. Vectors of randomly generated ints
  2. Vectors of randomly generated floats

Strings

  1. Check if a string contains any one of a number of characters
  2. Check if a string contains a given substring
  3. Working with filenames using string member functions
  4. Remove chars from a string

Lists

  1. Merge two lists using std::merge()
  2. Append a list to the end of another
  3. Remove elements using a filter

Vectors, including methods from <algorithms>, <functional>, <numeric>, etc.

  1. min_element(), max_element(), accumulate()
  2. Using std::accumulate
  3. Sort and comparator functions
  4. A Vector of vectors
  5. More vector of vectors
  6. Randomly shuffle elements in a vector or a list
  7. Rearrange a collection into the next lexicographical permutation

Deques

  1. Application: compute the running median

std::generate and function generators

  1. Generate elements in a sequence according to a rule

unordered_map and its uses

  1. Basic unordered_map examples
  2. Find word frequencies using unordered_map
  3. Check whether one map's keys exist in another map
  4. Application: Solving the classic interview problem "2-sum"
  5. Application: Solving the interview problem "Frequency Sort"
  6. Application: Solving the interview problem "LRU Cache"

unordered_set and its uses

  1. Application: zeroing-out select rows & cols using an unordered set

Data Structures: Graphs

  1. Breadth-first-search (BFS) of a graph
  2. Depth-first-search (DFS) of a graph

Data Structures: Linked-Lists

  1. A simple implementation of a singly-linked list
  2. Merge two singly-linked lists
  3. A class implementation of a singly-linked list

Algorithms: Search

  1. Binary Search

Algorithms: Sort

  1. Merge Sort
  2. Merge Sort using std::inplace_merge()

Other Competetive Programming & Interview Problem Solutions

  1. Reverse an Integer
  2. Container with the most water
  3. Implement atoi() to convert input string to 32-bit integer
  4. Longest Palindromic Substring

Classes

  1. Sort a vector of custom class objects by private member variable
  2. Filtering a collection

bitset and number base representations

  1. decimal-to-binary and binary-to-decimal conversions
  2. an recursive decimal-to-binary conversion function (meant only for amusement)

Functional Programming Examples

  1. Trimming whitespace around a string

Useful utility functions, etc.

  1. A variadic printing function for debugging
  2. A template printing function for vectors of different data types
  3. Starter source for competitive programming
much more to come ...