My Project
Functions
non_recursive_merge_sort.cpp File Reference
#include <cstddef>
#include <utility>
#include <iostream>
Include dependency graph for non_recursive_merge_sort.cpp:

Functions

template<class Iterator >
void merge (Iterator l, Iterator r, const Iterator e, char b[])
 merges 2 sorted adjacent segments into a larger sorted segment More...
 
template<class Iterator >
void non_recursive_merge_sort (const Iterator first, const Iterator last, const size_t n)
 bottom-up merge sort which sorts elements in a non-decreasing order More...
 
template<class Iterator >
void non_recursive_merge_sort (const Iterator first, const size_t n)
 bottom-up merge sort which sorts elements in a non-decreasing order More...
 
template<class Iterator >
void non_recursive_merge_sort (const Iterator first, const Iterator last)
 bottom-up merge sort which sorts elements in a non-decreasing order More...
 
int main (int argc, char **argv)
 

Detailed Description

Copyright 2020

Author
Albirair

A generic implementation of non-recursive merge sort.

Function Documentation

◆ merge()

template<class Iterator >
void merge ( Iterator  l,
Iterator  r,
const Iterator  e,
char  b[] 
)

merges 2 sorted adjacent segments into a larger sorted segment

best-case = worst-case = O(n)

Parameters
lpoints to the left part
rpoints to the right part, end of left part
epoints to end of right part
bpoints at the buffer

◆ non_recursive_merge_sort() [1/3]

template<class Iterator >
void non_recursive_merge_sort ( const Iterator  first,
const Iterator  last 
)

bottom-up merge sort which sorts elements in a non-decreasing order

Parameters
firstpoints to the first element
lastpoints to 1-step past the last element

◆ non_recursive_merge_sort() [2/3]

template<class Iterator >
void non_recursive_merge_sort ( const Iterator  first,
const Iterator  last,
const size_t  n 
)

bottom-up merge sort which sorts elements in a non-decreasing order

sorts elements non-recursively by breaking them into small segments, merging adjacent segments into larger sorted segments, then increasing the sizes of segments by factors of 2 and repeating the same process. best-case = worst-case = O(n log(n))

Parameters
firstpoints to the first element
lastpoints to 1-step past the last element
nthe number of elements

◆ non_recursive_merge_sort() [3/3]

template<class Iterator >
void non_recursive_merge_sort ( const Iterator  first,
const size_t  n 
)

bottom-up merge sort which sorts elements in a non-decreasing order

Parameters
firstpoints to the first element
nthe number of elements