Skip to content

Commit

Permalink
Merge pull request #129 from Alka-git12/master
Browse files Browse the repository at this point in the history
more algo in issue #1
  • Loading branch information
argonautica authored Jun 12, 2020
2 parents 67175bb + 615f036 commit 4a86992
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions C++/PigeonholeSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include<iostream>
#include<vector>
using namespace std;

void pigeonhole_sort(int arr[],int n)
{
int minm=arr[0],maxm=arr[0];
for(int i=1;i<n;i++)
{
if(arr[i]<minm)
minm=arr[i];
if(arr[i]>maxm)
maxm=arr[i];
}
int range=maxm-minm+1;
vector<int>holes[range];
for(int i=0;i<n;i++)
holes[arr[i]-minm].push_back(arr[i]);
int index=0;
for(int i=0;i<range;i++)
{
for(auto it:holes[i])
arr[index++]=it;
}
}

int main()
{
int n;
cout<<"Enter the size of array : ";
cin>>n;
int arr[n];
cout<<"Enter elements of the array : ";
for(int i=0;i<n;i++)
cin>>arr[i];
pigeonhole_sort(arr,n);
cout<<"Sorted array is : "<<endl;
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
return 0;
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Sorting Algorithms
# Sorting Algorithms
_Sorting algorithms implemented in different languages (for hacktoberfest_ 😃_). This repository is open to everyone. Feel free to add any sorting algorithms. The instructions for how to contribute to this repo are down below._

## List of Algorithms ⌨️
| Language | Algorithms |
|----------|------------|
| Assembly | [`Bubble Sort`](Assembly/bubblesort.asm) [`Quick Sort`](Assembly/quicksort.asm)
| C++ | [`Interchange Sort`](C++/InterchangeSort.cpp ) [`Bubble Sort`](C++/BubbleSort.cpp) [`Heap Sort`](C++/HeapSort.cpp) <br> [`Insertion Sort`](C++/InsertionSort.cpp) [`Merge Sort`](C++/MergeSort.cpp) [`Quick Sort`](C++/QuickSort.cpp) <br> [`Selection Sort`](C++/SelectionSort.cpp) [`Shell Sort`](C++/ShellSort.cpp) [`Binary Insertion Sort`](C++/BinaryInsertionSort.cpp) <br> [`Bucket Sort`](C++/BucketSort.cpp) [`Cycle Sort`](C++/cycleSort.cpp) [`K Way Merge Sort`](C++/) <br> [`Radix Sort`](C++/RadixSort.cpp) [`Tree Sort`](C++/treeSort.cpp) |
| C++ | [`Interchange Sort`](C++/InterchangeSort.cpp ) [`Bubble Sort`](C++/BubbleSort.cpp) [`Heap Sort`](C++/HeapSort.cpp) <br> [`Insertion Sort`](C++/InsertionSort.cpp) [`Merge Sort`](C++/MergeSort.cpp) [`Quick Sort`](C++/QuickSort.cpp) <br> [`Selection Sort`](C++/SelectionSort.cpp) [`Shell Sort`](C++/ShellSort.cpp) [`Binary Insertion Sort`](C++/BinaryInsertionSort.cpp) <br> [`Bucket Sort`](C++/BucketSort.cpp) [`Cycle Sort`](C++/cycleSort.cpp) [`K Way Merge Sort`](C++/) <br> [`Radix Sort`](C++/RadixSort.cpp) [`Tree Sort`](C++/treeSort.cpp) [`PigeonholeSort`](C++/PigeonholeSort.cpp) |
| C | [`Bubble Sort`](C/BubbleSort.c) [`Insertion Sort`](C/InsertionSort.c) [`Merge Sort`](C/MergeSort.c) <br> [`Quick Sort`](C/QuickSort.c) [`Selection Sort`](C/SelectionSort.c) [`Bubble Sort #2`](C/Bubble-Sort.c) <br>[`Gnome Sort`](C/gnomesort.c) [`Heap Sort`](C/heapsort.c) [`Radix Sort`](C/radixsort.c) <br> [`Tree Sort`](C/treesort.c) |
| C# | [`Bubble Sort`](C#/BubbleSort.cs) [`Binary Insertion Sort`](C#/BinaryInsertionSort.cs) [`Heap Sort`](C#/HeapSort.cs) <br> [`Insertion Sort`](C#/InsertionSort.cs) [`Merge Sort`](C#/MergeSort.cs) [`Quick Sort`](C#/QuickSort.cs) <br> [`Selection Sort`](C#/SelectionSort.cs) [`Shell Sort`](C#/ShellSort.cs) |
| Go | [`Radix Sort`](Go/RadixSort.go) [`Bubble Sort`](Go/BubbleSort.go) [`Insertion Sort`](Go/InsertionSort.go)|
Expand Down

0 comments on commit 4a86992

Please sign in to comment.