-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (25 loc) · 829 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import Any, List
from sorters import *
if __name__ == "__main__":
# Create a list of User instances.
users: List[User] = [
User("Alice", 30),
User("Bob", 25),
User("Charlie", 25),
User("Dave", 35),
User("Eve", 30),
]
# Initialize a MinHeap instance.
minheap = MinHeap()
# Insert users into the heap
for user in users:
minheap.insert(user) # Add each user to the heap.
# Prepare to extract and display users in order.
sorted_users: List[Any] = []
# Extract users from the heap until it is empty.
while not minheap.is_empty():
sorted_users.append(minheap.extract_min())
# Print the sorted users
print("Sorted users:")
for user in sorted_users:
print(user) # Print each user in sorted order.