bucket : buckets) {
+ for (int value : bucket) {
+ arr[index++] = value;
+ }
+ }
+
+ return arr;
+ }
+}
diff --git a/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/Greeting.java b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/Greeting.java
new file mode 100644
index 0000000..7247ce3
--- /dev/null
+++ b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/Greeting.java
@@ -0,0 +1,11 @@
+package org.example.websortingalgo.service;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class Greeting {
+ public String greet(String name) {
+ return "Hello, " + name + "!";
+ }
+
+}
diff --git a/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/HeapSortService.java b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/HeapSortService.java
new file mode 100644
index 0000000..fa35625
--- /dev/null
+++ b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/HeapSortService.java
@@ -0,0 +1,48 @@
+package org.example.websortingalgo.service;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class HeapSortService {
+
+ public int[] sort(String algorithm, int[] array){
+ int n = array.length;
+
+ // Build heap (rearrange array)
+ for (int i = n / 2 - 1; i >= 0; i--)
+ heapify(array, n, i);
+
+ // One by one extract an element from heap
+ for (int i = n - 1; i > 0; i--) {
+ // Move current root to end
+ int temp = array[0];
+ array[0] = array[i];
+ array[i] = temp;
+
+ // Call max heapify on the reduced heap
+ heapify(array, i, 0);
+ }
+ return array;
+ }
+
+ private void heapify(int[] arr, int n, int i) {
+ int largest = i;
+ int left = 2 * i + 1;
+ int right = 2 * i + 2;
+
+ if (left < n && arr[left] > arr[largest])
+ largest = left;
+
+ if (right < n && arr[right] > arr[largest])
+ largest = right;
+
+ if (largest != i) {
+ int swap = arr[i];
+ arr[i] = arr[largest];
+ arr[largest] = swap;
+
+ heapify(arr, n, largest);
+ }
+ }
+
+}
diff --git a/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/MergeSortService.java b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/MergeSortService.java
new file mode 100644
index 0000000..32d7fc5
--- /dev/null
+++ b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/MergeSortService.java
@@ -0,0 +1,46 @@
+package org.example.websortingalgo.service;
+import org.springframework.stereotype.Service;
+
+
+@Service
+public class MergeSortService {
+
+ public int[] sort(String algorithm, int[] arr) {
+ mergeSort(arr, 0, arr.length - 1);
+ return arr;
+ }
+
+ private void mergeSort(int[] arr, int left, int right) {
+ if (left < right) {
+ int mid = (left + right) / 2;
+
+ mergeSort(arr, left, mid);
+ mergeSort(arr, mid + 1, right);
+
+ merge(arr, left, mid, right);
+ }
+ }
+
+ private void merge(int[] arr, int left, int mid, int right) {
+ int[] temp = new int[right - left + 1];
+ int i = left, j = mid + 1, k = 0;
+
+ while (i <= mid && j <= right) {
+ if (arr[i] <= arr[j]) {
+ temp[k++] = arr[i++];
+ } else {
+ temp[k++] = arr[j++];
+ }
+ }
+
+ while (i <= mid) {
+ temp[k++] = arr[i++];
+ }
+
+ while (j <= right) {
+ temp[k++] = arr[j++];
+ }
+
+ System.arraycopy(temp, 0, arr, left, temp.length);
+ }
+}
diff --git a/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/QuickSort.java b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/QuickSort.java
new file mode 100644
index 0000000..43fd29d
--- /dev/null
+++ b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/QuickSort.java
@@ -0,0 +1,41 @@
+package org.example.websortingalgo.service;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class QuickSort {
+
+ public int[] sort(String algorithm, int[] arr) {
+ quickSort(arr, 0, arr.length - 1);
+ return arr;
+ }
+
+ private void quickSort(int[] arr, int low, int high) {
+ if (low < high) {
+ int partitionIndex = partition(arr, low, high);
+
+ quickSort(arr, low, partitionIndex - 1);
+ quickSort(arr, partitionIndex + 1, high);
+ }
+ }
+
+ private 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;
+ }
+}
diff --git a/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/RadixSortService.java b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/RadixSortService.java
new file mode 100644
index 0000000..2191fb5
--- /dev/null
+++ b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/RadixSortService.java
@@ -0,0 +1,60 @@
+package org.example.websortingalgo.service;
+
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+
+
+/**
+ * Service that provides functionality to perform Radix Sort on an array of integers.
+ * Radix Sort is a non-comparative sorting algorithm that processes each digit of the numbers.
+ * It uses a stable intermediate sorting algorithm (Counting Sort) for each digit in the numbers.
+ */
+@Service
+public class RadixSortService {
+
+ /**
+ * Sorts the given array of integers using the Radix Sort algorithm.
+ * The sorting is done by processing each digit of the numbers starting from the least significant digit (LSD).
+ *
+ * @param algorithm The name of the algorithm (not used in this implementation, but could be for logging or future enhancements).
+ * @param arr The array of integers to be sorted.
+ * @return The sorted array of integers.
+ * @throws IllegalArgumentException If the input array is null or empty.
+ */
+ public int[] sort(String algorithm, int[] arr) {
+
+ if (algorithm.isEmpty() || arr == null || arr.length == 0) {
+ throw new IllegalArgumentException("Input array must not be null or empty.");
+ }
+ int max = Arrays.stream(arr).max().orElse(0);
+
+ for (int exp = 1; max / exp > 0; exp *= 10) {
+ countingSort(arr, exp);
+ }
+ return arr;
+ }
+
+ private void countingSort(int[] arr, int exp) {
+ int n = arr.length;
+ int[] output = new int[n];
+ int[] count = new int[10];
+
+ Arrays.fill(count, 0);
+
+ for (int j : arr) {
+ count[(j / exp) % 10]++;
+ }
+
+ for (int i = 1; i < 10; i++) {
+ count[i] += count[i - 1];
+ }
+
+ for (int i = n - 1; i >= 0; i--) {
+ output[count[(arr[i] / exp) % 10] - 1] = arr[i];
+ count[(arr[i] / exp) % 10]--;
+ }
+
+ System.arraycopy(output, 0, arr, 0, n);
+ }
+}
diff --git a/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/SortingService.java b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/SortingService.java
new file mode 100644
index 0000000..229583c
--- /dev/null
+++ b/WebSortingAlgo/src/main/java/org/example/websortingalgo/service/SortingService.java
@@ -0,0 +1,93 @@
+package org.example.websortingalgo.service;
+
+import org.example.websortingalgo.dto.SortingRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+/**
+ * Service class that handles sorting requests and delegates sorting to appropriate sorting algorithm services.
+ *
+ * This class is responsible for receiving a sorting request, choosing the appropriate sorting algorithm based on the
+ * user's input, and returning the sorted data. It supports multiple sorting algorithms such as Bucket Sort, Merge Sort,
+ * Quick Sort, Heap Sort, and Radix Sort.
+ *
+ */
+@Service
+public class SortingService {
+ private final BucketSortService bucketSortService;
+ private final MergeSortService mergeSortService;
+ private final QuickSort quickSort;
+ private final HeapSortService heapSortService;
+ private RadixSortService radixSortService;
+
+
+ @Autowired
+ public SortingService(BucketSortService bucketSortService,
+ MergeSortService mergeSortService, QuickSort quickSort,
+ HeapSortService heapSortService,
+ RadixSortService radixSortService) {
+ this.bucketSortService = bucketSortService;
+ this.mergeSortService = mergeSortService;
+ this.quickSort = quickSort;
+ this.heapSortService = heapSortService;
+ this.radixSortService = radixSortService;
+ }
+
+ /**
+ * Handles the sorting of data based on the user's request.
+ *
+ * @param sortingRequest the sorting request containing algorithm, order, and data to be sorted
+ * @return a map containing the sorted data, the algorithm used, and the order of sorting
+ * @throws if an unsupported sorting algorithm is requested
+ * @throws if the data provided is invalid or empty
+ */
+ public Map handleSorting(SortingRequest sortingRequest) {
+ String algorithm = sortingRequest.getAlgorithm();
+ String order = sortingRequest.getOrder();
+ List data = sortingRequest.getData();
+
+ //validate inputs
+ if(data == null || data.isEmpty()){
+ throw new NullPointerException("data is null or empty");
+ }
+
+ // Convert the list to an array
+ int[] inputArray = data.stream().mapToInt(Integer::intValue).toArray();
+
+ // Delegate sorting to the appropriate service
+ int[] sortedArray;
+ switch (algorithm.toLowerCase()) {
+ case "bucket":
+ sortedArray = bucketSortService.sort(algorithm, inputArray);
+ break;
+ case "merge":
+ sortedArray = mergeSortService.sort(algorithm, inputArray);
+ break;
+ case "quick":
+ sortedArray = quickSort.sort(algorithm, inputArray);
+ break;
+ case "heap":
+ sortedArray = heapSortService.sort(algorithm, inputArray);
+ break;
+ case "radix":
+ sortedArray = radixSortService.sort(algorithm, inputArray);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported algorithm: " + algorithm);
+ }
+
+ // Prepare the response
+ Map response = new HashMap<>();
+ response.put("sorted_data", Arrays.stream(sortedArray).boxed().collect(Collectors.toList()));
+ response.put("algorithm", algorithm);
+ response.put("order", order);
+ return response;
+ }
+}
diff --git a/WebSortingAlgo/src/main/java/org/example/websortingalgo/util/HatoesClass.java b/WebSortingAlgo/src/main/java/org/example/websortingalgo/util/HatoesClass.java
new file mode 100644
index 0000000..5cc2d93
--- /dev/null
+++ b/WebSortingAlgo/src/main/java/org/example/websortingalgo/util/HatoesClass.java
@@ -0,0 +1,35 @@
+package org.example.websortingalgo.util;
+
+
+
+import org.springframework.hateoas.EntityModel;
+import org.springframework.hateoas.Link;
+import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
+import org.example.websortingalgo.controller.Controller;
+import org.example.websortingalgo.dto.SortingRequest;
+
+import java.util.Map;
+
+public class HatoesClass {
+
+ // Reusable helper method to add links to any sorting response
+ public static EntityModel