Skip to content

Commit

Permalink
Merge pull request #45 from sattya19/main
Browse files Browse the repository at this point in the history
added SortingJava resolved merge conflicts
  • Loading branch information
HarshwardhanPatil07 authored Oct 12, 2023
2 parents 0fa19b3 + eec2e11 commit b1f7f7e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<h1>✨Happy Hacktoberfest 2023✨</h1>
<p>Hacktoberfest is a yearly event whiich encourages not only programmers and coders but also non-technical background to contribute in open source and start their journey with open source.</p>
<h1>Star Repo is Mandatory for Hactober Accepting!</h1>
<h1>Star Repo is Mandatory for Hactober Accepting!</h1>

# Message

<p>Enter your Name, Github Link in the given format. Don't try to change anything else!!!</p>
<code>| Name | Github Link |</code>

Expand All @@ -25,4 +26,4 @@
| Kevin Malik Fajar | <a href="https://github.com/kevinmf1"> Kevin Malik Fajar </a>|
| Jeelwin | <a href="https://github.com/jeelwin"> Jeelwin </a>|
| Marina J | <a href="https://github.com/marinajcs"> marinajcs </a>|
| Diapk Kurkute| <a href="https://github.com/dipak-01"> dipak-01 </a>|
| Diapk Kurkute| <a href="https://github.com/dipak-01"> dipak-01 </a>|
30 changes: 30 additions & 0 deletions Python/Sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ def radix_sort(self):

buckets = [[] for _ in range(10)]



def counting_sort(self):

max_num = max(self.arr)
min_num = min(self.arr)
range_of_values = max_num - min_num + 1

count = [0] * range_of_values
output = [0] * len(self.arr)

for num in self.arr:
count[num - min_num] += 1

for i in range(1, range_of_values):
count[i] += count[i - 1]

for num in reversed(self.arr):
output[count[num - min_num] - 1] = num
count[num - min_num] -= 1

self.arr = output


# Base example array
arr = [64, 34, 25, 12, 22, 11, 90]

Expand Down Expand Up @@ -186,4 +210,10 @@ def radix_sort(self):
print("\nRadix Sort -")
sorting_obj = SortingAlgorithms(arr) # Reset the array
sorting_obj.radix_sort()
sorting_obj.display()

# Counting Sort
print("\nCounting Sort -")
sorting_obj = SortingAlgorithms(arr) # Reset the array
sorting_obj.counting_sort()
sorting_obj.display()
51 changes: 51 additions & 0 deletions SortingJava/QuickSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package SortingJava;

public class QuickSort {
public static void quickSort(int[] arr) {
quickSort(arr, 0, arr.length - 1);
}

private static void quickSort(int[] arr, int low, int high) {
if (low < high) {
int pivotIndex = partition(arr, low, high);
quickSort(arr, low, pivotIndex - 1);
quickSort(arr, pivotIndex + 1, high);
}
}

private static int partition(int[] arr, int low, int high) {
int pivot = arr[high];
int i = low - 1;

for (int j = low; j < high; j++) {
if (arr[j] < pivot) {
i++;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}

int temp = arr[i + 1];
arr[i + 1] = arr[high];
arr[high] = temp;

return i + 1;
}

public static void main(String[] args) {
int[] arr = { 24, 9, 29, 14, 19, 27 };
System.out.println("Before quick sort:");
printArray(arr);
quickSort(arr);
System.out.println("After quick sort:");
printArray(arr);
}

public static void printArray(int[] arr) {
for (int num : arr) {
System.out.print(num + " ");
}
System.out.println();
}
}

0 comments on commit b1f7f7e

Please sign in to comment.