From b54985763ccf714e21fc11f06a08df39ce5972d7 Mon Sep 17 00:00:00 2001 From: Nishant Sagar Date: Wed, 19 Mar 2025 13:01:57 +0530 Subject: [PATCH 1/2] Add Merge Sort --- Sorting/mergesort.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Sorting/mergesort.py 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) From 4f75c96b97beadc79dbad65cdf330617ca6f3d19 Mon Sep 17 00:00:00 2001 From: Nishant Sagar Date: Thu, 20 Mar 2025 06:59:34 +0530 Subject: [PATCH 2/2] Add README file for TCP Chat Server --- TCP Chat Server/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 TCP Chat Server/README.md 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