TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Files | |
file | merge_sort.cpp |
Merege Sort Algorithm (MEREGE SORT) implementation | |
file | wiggle_sort.cpp |
[Wiggle Sort Algorithm] (https://leetcode.com/problems/wiggle-sort-ii/) Implementation | |
Namespaces | |
namespace | sorting |
for working with vectors | |
Functions | |
template<typename T > | |
void | heapify (T *arr, int n, int i) |
template<typename T > | |
void | heapSort (T *arr, int n) |
void | merge (int *arr, int l, int m, int r) |
void | mergeSort (int *arr, int l, int r) |
void | show (int *arr, int size) |
int | main () |
template<typename T > | |
static void | displayElements (const std::vector< T > &arr) |
Utility function used for printing the elements. Prints elements of the array after they're sorted using wiggle sort algorithm. | |
static void | test () |
The heapify procedure can be thought of as building a heap from the bottom up by successively sifting downward to establish the heap property.
arr | array to be sorted |
n | size of array |
i | node position in Binary Tress or element position in Array to be compared with it's childern |
|
static |
Utility function used for printing the elements. Prints elements of the array after they're sorted using wiggle sort algorithm.
arr | array containing the sorted elements |
Definition at line 86 of file wiggle_sort.cpp.
void heapify | ( | T * | arr, |
int | n, | ||
int | i ) |
Definition at line 58 of file heap_sort.cpp.
void heapSort | ( | T * | arr, |
int | n ) |
Utilizes heapify procedure to sort the array
arr | array to be sorted |
n | size of array |
Definition at line 84 of file heap_sort.cpp.
int main | ( | void | ) |
Main function
Driver Code
Definition at line 90 of file merge_sort.cpp.
void merge | ( | int * | arr, |
int | l, | ||
int | m, | ||
int | r ) |
The merge() function is used for merging two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into one.
arr | - array with two halves arr[l...m] and arr[m+1...r] |
l | - left index or start index of first half array |
m | - right index or end index of first half array |
(The second array starts form m+1 and goes till r)
r | - end index or right index of second half array |
Definition at line 33 of file merge_sort.cpp.
void mergeSort | ( | int * | arr, |
int | l, | ||
int | r ) |
Merge sort is a divide and conquer algorithm, it divides the input array into two halves and calls itself for the two halves and then calls merge() to merge the two halves
arr | - array to be sorted |
l | - left index or start index of array |
r | - right index or end index of array |
Definition at line 71 of file merge_sort.cpp.
void show | ( | int * | arr, |
int | size ) |
Utility function used to print the array after sorting
Definition at line 84 of file merge_sort.cpp.
|
static |
Test function
Definition at line 107 of file wiggle_sort.cpp.