Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create StalinSort.cpp #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

FreshMess
Copy link

The Stalin Sort algorithm works by iterating through the input vector and removing any elements that are not in sorted order, keeping only the elements that are in order. In this implementation, we start by assuming that the first element in the vector is the largest and compare all subsequent elements to it. If an element is smaller than the current maximum, it is not in sorted order and is removed from the vector. Otherwise, it becomes the new maximum and is kept in the vector.

The stalinSort function takes a reference to a vector of integers as input and modifies it in place to contain only the sorted elements. The main function creates an example vector, prints it to the console, sorts it using stalinSort, and prints the sorted vector to the console.

The Stalin Sort algorithm works by iterating through the input vector and removing any elements that are not in sorted order, keeping only the elements that are in order. In this implementation, we start by assuming that the first element in the vector is the largest and compare all subsequent elements to it. If an element is smaller than the current maximum, it is not in sorted order and is removed from the vector. Otherwise, it becomes the new maximum and is kept in the vector.

The stalinSort function takes a reference to a vector of integers as input and modifies it in place to contain only the sorted elements. The main function creates an example vector, prints it to the console, sorts it using stalinSort, and prints the sorted vector to the console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant