Implementations of data structures and algorithms using C++ by Junkang Huang.
A simple tool using std::chrono
to measure how long a program runs. And you can set multiple checkpoints conveniently in a program.
Print vector in various mode to given ostream object.
Swap two elements in a vector.
Draw histogram directly on terminal.
Class template implementation of linked list.
But you cannot use iterator here. Use pointer to myList<T>::node
instead.
Pay special attention to friend declaration and class template.
Use std::vector
to implement stack data structure.
Use std::vector
would be much too easy. Instead, I use circular fundamental array to implement queue.
General binary tree node structure, with only copy and move constructors (no default constructor)
A function to convert an infix expression to postfix expression
Expression Tree Implementation:
Using myBinaryTreeNode
template and use std::string
to instantiate it
In expression tree, leaf node contain operand strings and non-leaf node contain operators (in string).
Expression public routines include three expression notation: prefix, infix, postfix
By now, only support binary operators: +, -, *, /
Binary search tree(BST) implementation, containing an inner node structure.
AVL Tree, a balanced type of binary search tree. With height recorded in each node and an additional balance routine. Balance routine include single rotation and double rotation, which is critical for AVL tree.
Splay tree, from top down implementation. None recursive element reference.
A test routine to evaluate performance of a tree template. Template should support int type element, and tolerate repeat insertion.
Seperate chaining hash table implementation.
Probing hash table implementation.
A minimum heap (priority queue) implementation.
Using std::vector
to store values.
Leftist Heap implementation.
Right most path is the shortest path.
merge()
function is vital.
Bubble sort implementation.
Insertion sort implementation.
Shell sort implementation. Using Hibbard increment sequence.
Using heap to get the maximum element out one by one, then put them at the heap vector from back forward. No extra space needed.
Merge sort implementation. Using a common temperary std::vector to store temperary values. Rather than creating one more vector each calling.
Classic quick sort implementation. Using a cutoff strategy, for small size input, use insertion sort. You are free to set the cutoff value.
A routine to evaluate performance of sort function.
Use myHist()
to show result in histogram.
Disjoint set class. An compact and nice implementation of union
and find
function.
Used in Kruskal algorithm.
Including:
topSort()
: top sort algorithms
minPathUnweighted()
: Find the minimum unweighted distance from start vertices to each vertices.
minPathWeightedNegative()
:Find the minimum weighted distance from start vertex to each vertices
Dijkstra()
: Dijkstra algorithm implementation. Without heap optimization.
DijkstraNoCycle()
: Improved Dijkstra algorithm for noncycle graph
maxFlow()
: Maximum net flow algorithm.
Prim()
: Prim algorithm for minimum spanning tree problem.
Kruskal()
: Kruskal algorithm.
Input: N numbers (not sorted)
Output: the k-th largest number of input
Using std::priority_queue
.
A simple tools to check brace balance of a file.
Using std::stack
.
Using std::stack
to calculate a postfix expression which is inputed as a std::string.
Using std::stack
to translate a infix expression into corresponding postfix expression.
Then using myPostfixCalculator()
to calculate the result.