Skip to content

algocpp::algorithm::stalin_sort

sakamotor edited this page Aug 8, 2023 · 1 revision

algocpp::algorithm::stalin_sort

Description

Perform Stalin sort on std::vector, etc.

Time

Assuming the number of elements to be $N$, approximately $O(N)$

Example

#include <iostream>
#include <vector>
#include <algocpp/algorithm.hpp>
#include <algocpp/io.hpp>
using namespace std;

int main()
{
    vector<int> A = {1, 3, 3, 5, 4, 7, 1, 9};

    // [1, 3, 3, 5, 7, 9]
    cout << algocpp::algorithm::stalin_sort(A, false) << endl;

    // [1, 3, 5, 7, 9]
    cout << algocpp::algorithm::stalin_sort(A, true) << endl;
}
Clone this wiki locally