diff --git a/Sorting/mergesort.py b/Sorting/mergesort.py new file mode 100644 index 00000000..ae8012fa --- /dev/null +++ b/Sorting/mergesort.py @@ -0,0 +1,46 @@ +class MergeSort: + def __init__(self, array): + self.array = array + + def sort(self): + self.array = self.merge_sort(self.array) + return self.array + + def merge_sort(self, arr): + if len(arr) <= 1: + return arr + + mid = len(arr) // 2 + left_half = self.merge_sort(arr[:mid]) + right_half = self.merge_sort(arr[mid:]) + + return self.merge(left_half, right_half) + + def merge(self, left, right): + sorted_arr = [] + i = j = 0 + + while i < len(left) and j < len(right): + if left[i] < right[j]: + sorted_arr.append(left[i]) + i += 1 + else: + sorted_arr.append(right[j]) + j += 1 + + while i < len(left): + sorted_arr.append(left[i]) + i += 1 + + while j < len(right): + sorted_arr.append(right[j]) + j += 1 + + return sorted_arr + +# Example usage +if __name__ == "__main__": + arr = [38, 27, 43, 3, 9, 82, 10] + merge_sort = MergeSort(arr) + sorted_array = merge_sort.sort() + print("Sorted array:", sorted_array) diff --git a/TCP Chat Server/README.md b/TCP Chat Server/README.md new file mode 100644 index 00000000..28019c92 --- /dev/null +++ b/TCP Chat Server/README.md @@ -0,0 +1,18 @@ +# TCP Chat Server + +A simple TCP server that listens for client connections and receives messages. This server can be used with **Netcat (`nc`)** or any other TCP client. + +--- + +## 🚀 Features +- Handles incoming client connections. +- Receives messages in real-time. +- Prevents address reuse errors (`OSError: Address already in use`). +- Works with **Netcat (`nc`)** or any TCP client. + +--- + +## 🛠️ Installation & Setup +- Navigate to 'TCP Chat Server' directory and run python3 server.py +- To test the connection open a new terminal and run nc localhost 3000 +- Type the message here, it will be reflected in the first terminal \ No newline at end of file