Skip to content

Added Merge Sort in the Sorting directory #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Sorting/mergesort.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions TCP Chat Server/README.md
Original file line number Diff line number Diff line change
@@ -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