From 2d75886f46151b3899893fa0f7973946f16f8a4f Mon Sep 17 00:00:00 2001 From: Aruj Sharma Date: Tue, 2 Oct 2018 09:31:26 +0530 Subject: [PATCH 1/6] Create StoogeSort.c --- Sorts/StoogeSort.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Sorts/StoogeSort.c diff --git a/Sorts/StoogeSort.c b/Sorts/StoogeSort.c new file mode 100644 index 00000000..8b265adb --- /dev/null +++ b/Sorts/StoogeSort.c @@ -0,0 +1,37 @@ +#include +void stoogesort(int [], int, int); + +void main() +{ + int arr[100], i, n; + + printf("How many elements do you want to sort: "); + scanf("%d", &n); + for (i = 0;i < n; i++) + scanf(" %d", &arr[i]); + stoogesort(arr, 0, n - 1); + printf("Sorted array : \n"); + for (i = 0;i < n;i++) + { + printf("%d ", arr[i]); + } + printf("\n"); +} + + +void stoogesort(int arr[], int i, int j) +{ + int temp, k; + if (arr[i] > arr[j]) + { + temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + if ((i + 1) >= j) + return; + k = (int)((j - i + 1) / 3); + stoogesort(arr, i, j - k); + stoogesort(arr, i + k, j); + stoogesort(arr, i, j - k); +} From ab034437bab92a688c38c48fd266e47c3a255f60 Mon Sep 17 00:00:00 2001 From: Aruj Sharma Date: Tue, 2 Oct 2018 09:40:23 +0530 Subject: [PATCH 2/6] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fcc41876..063d7dd4 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ - SelectionSort - shaker_sort - HeapSort + - StoogeSort ## Hashing - sdbm From 234f68093f4e93346a8859ae57d398b628fae5ca Mon Sep 17 00:00:00 2001 From: Aruj Sharma Date: Tue, 2 Oct 2018 09:56:10 +0530 Subject: [PATCH 3/6] Create RadixSort.c --- Sorts/RadixSort.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Sorts/RadixSort.c diff --git a/Sorts/RadixSort.c b/Sorts/RadixSort.c new file mode 100644 index 00000000..9ceca1a9 --- /dev/null +++ b/Sorts/RadixSort.c @@ -0,0 +1,74 @@ +#include + +int largest(int a[], int n) +{ + int large = a[0], i; + for(i = 1; i < n; i++) + { + if(large < a[i]) + large = a[i]; + } + return large; +} + + +void RadixSort(int a[], int n) +{ + int bucket[10][10], bucket_count[10]; + int i, j, k, remainder, NOP=0, divisor=1, large, pass; + + large = largest(a, n); + printf("The large element %d\n",large); + while(large > 0) + { + NOP++; + large/=10; + } + + for(pass = 0; pass < NOP; pass++) + { + for(i = 0; i < 10; i++) + { + bucket_count[i] = 0; + } + for(i = 0; i < n; i++) + { + remainder = (a[i] / divisor) % 10; + bucket[remainder][bucket_count[remainder]] = a[i]; + bucket_count[remainder] += 1; + } + + i = 0; + for(k = 0; k < 10; k++) + { + for(j = 0; j < bucket_count[k]; j++) + { + a[i] = bucket[k][j]; + i++; + } + } + divisor *= 10; + + for(i = 0; i < n; i++) + printf("%d ",a[i]); + printf("\n"); + } +} + +int main() +{ + int i, n, a[10]; + printf("Enter the number of elements :: "); + scanf("%d",&n); + printf("Enter the elements :: "); + for(i = 0; i < n; i++) + { + scanf("%d",&a[i]); + } + RadixSort(a,n); + printf("The sorted elements are :: "); + for(i = 0; i < n; i++) + printf("%d ",a[i]); + printf("\n"); + return 0; +} From 66395160820b749c4e8be46d22e1fa92312db8ff Mon Sep 17 00:00:00 2001 From: Aruj Sharma Date: Tue, 2 Oct 2018 09:56:50 +0530 Subject: [PATCH 4/6] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 063d7dd4..d84704d3 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ - shaker_sort - HeapSort - StoogeSort + - RadixSort ## Hashing - sdbm From 5e9189be5d4be4bfea3ab7a5dbfde82476bbb43f Mon Sep 17 00:00:00 2001 From: Ashwek Swamy <39827514+ashwek@users.noreply.github.com> Date: Wed, 30 Oct 2019 14:21:05 +0530 Subject: [PATCH 5/6] Rename Sorts/StoogeSort.c to sorting/StoogeSort.c --- {Sorts => sorting}/StoogeSort.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Sorts => sorting}/StoogeSort.c (100%) diff --git a/Sorts/StoogeSort.c b/sorting/StoogeSort.c similarity index 100% rename from Sorts/StoogeSort.c rename to sorting/StoogeSort.c From f8a5c1485211c6991ba1cc7403c69cc0120e2ec8 Mon Sep 17 00:00:00 2001 From: Ashwek Swamy <39827514+ashwek@users.noreply.github.com> Date: Wed, 30 Oct 2019 14:22:29 +0530 Subject: [PATCH 6/6] Rename Sorts/RadixSort.c to sorting/radix_sort.c --- Sorts/RadixSort.c => sorting/radix_sort.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Sorts/RadixSort.c => sorting/radix_sort.c (100%) diff --git a/Sorts/RadixSort.c b/sorting/radix_sort.c similarity index 100% rename from Sorts/RadixSort.c rename to sorting/radix_sort.c