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

Pigeon hole sort #139

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
44 changes: 44 additions & 0 deletions c++/pigeonholesort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);

void pigeonsort(int arr, int n){
int min= *min_element(arr,arr+n);
int max=*max_element(arr,arr+n);
int range= max-min+1;
vector <int> v;
for (int i = 0; i < n; i++)
v[arr[i] - min].push_back(arr[i]);

int t=0;
for (int i = 0; i < range; i++) {
vector<int>::iterator it;
for (it = v[i].begin(); it != v[i].end(); ++it)
arr[index++] = *it;
}


for(int i=0;i<n;i++){cout<<arr[i];}




}





int main(){
fast
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
pigeonsort(arr,n);


return 0;
}
Empty file added c++/pigeonholesorting.cpp
Empty file.
1 change: 1 addition & 0 deletions csoc-2021-algorithms
Submodule csoc-2021-algorithms added at 98db0d