TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
non_recursive_merge_sort.cpp File Reference
#include <cstddef>
#include <iostream>
#include <utility>
Include dependency graph for non_recursive_merge_sort.cpp:

Go to the source code of this file.

Namespaces

namespace  sorting
 for working with vectors
 

Functions

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

Detailed Description

Copyright 2020

Author
Albirair

A generic implementation of non-recursive merge sort.

Definition in file non_recursive_merge_sort.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 94 of file non_recursive_merge_sort.cpp.

94 {
95 int size;
96 std::cout << "Enter the number of elements : ";
97 std::cin >> size;
98 int* arr = new int[size];
99 for (int i = 0; i < size; ++i) {
100 std::cout << "arr[" << i << "] = ";
101 std::cin >> arr[i];
102 }
103 non_recursive_merge_sort(arr, size);
104 std::cout << "Sorted array\n";
105 for (int i = 0; i < size; ++i)
106 std::cout << "arr[" << i << "] = " << arr[i] << '\n';
107 delete[] arr;
108 return 0;
109}