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

Added Calm Sort Funny Algorithm using C++ #1343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions sort/Calmly_sort/calm_sort_funny.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <iostream>
#include <vector>
using namespace std;
/*
*Welcome to Calmly Sorting! Here we are sorting values entered by the user
*and sorting them in ascending order. We don't have to rush everything in life, sometimes it's nice
*to take things slow and really visualize the process!!
*/
void calm_sort(vector<int>& arr) {
cout << "Starting Calm Sort... Let's take it slow and step by step and not rush! Time to relax and learn slowly!"<< endl;
cin.get(); //makes user click enter before continuing (keeps things interactive!)
//loops through list given by user
for (size_t i = 0; i < arr.size(); i++) {
cin.get();
cout << "Understanding value " << arr[i] << "... thinking and contemplating life..."<<endl;
cin.get();
//compares current value to other values in list
for (size_t j = i+1; j < arr.size(); j++) {
if(arr[i] > arr[j]) {
cout <<"There we go, time to SWAP! "<< arr[i]<< " with "<< arr[j]<<endl;
swap(arr[i], arr[j]);
cin.get();
} else {
cout<< "Value"<<" " << arr[i] << " and value " <<"" << arr[j] << " are fine where they are. No need to SWAP. Let's move on :)" << endl;
cin.get();
}
}
}
// complete message
cout<< "YAY! Sorting complete. That was quite a fast journey... right? ... YAY??.."<< endl;
cin.get();
}


int main() {
vector<int> arr;
int user_values;
//asks user to enter # of values
cout<< "Welcome to Calmly Sort! Please enter the number of values you want to enter and sort: ";
cin >> user_values;
// user enters their specific numbers they would like to sort
cout << "Please enter " <<user_values << " numbers:" << endl;
for (int i =0; i <user_values; ++i) {
int value;
cin>>value;
arr.push_back(value);
}
cout <<"Original List: ";
for (int n :arr) cout << n << " ";
cout << endl;

//call function to start sorting
calm_sort(arr);

cout << "Sorted List: " ;
for (int n :arr) cout << n << " ";
cout << endl;
return 0;
}