[1] task-1 #172

Open
lukovnikovde wants to merge 27 commits from lukovnikovde/2026-rff_mp:1-st-exercise into develop
Showing only changes of commit ddaef4333a - Show all commits

View File

@ -6,7 +6,7 @@ def sort_list(name_list):
for i in range(l - 1):
for j in range(l - i - 1):
if name_list[j][0] > name_list[j + 1][0]:
name_list[j][0], name_list[j + 1][0] = name_list[j + 1][0], name_list[j][0]
name_list[j], name_list[j + 1] = name_list[j + 1], name_list[j]
return name_list
@ -62,7 +62,7 @@ def ll_list_all(head):
name_list = []
running = head
while running is not None:
name_list.append([running['name'], running['phone']])
name_list.append((running['name'], running['phone']))
running = running['next']
return name_list
@ -117,9 +117,27 @@ def ht_insert(buckest, name, phone):
buckest[index].append((name, phone))
return buckest
def ht_find(buckest, name):
index = sum(ord(ch) for ch in name) % 10
for (Name, Phone) in buckest[index]:
if Name == name:
return Phone
return None
def ht_list_all(buckest):
name_list = []
for index in range(len(buckest)):
for i, (name, phone) in enumerate(buckest[index]):
name_list.append((name, phone))
name_list = sort_list(name_list)
return name_list
####################################################################################################
def HashTable(head):
def HashTable(buckest):
print('=========== TESTING HT_INSERT =============')
Name = ['Dima', 'Alex', 'Ivan', 'Maxim', 'Olga', 'Lena']
@ -130,18 +148,26 @@ def HashTable(head):
str(rnd.randint(0,9)) + str(rnd.randint(0,9)) + str(rnd.randint(0,9))
print(name, phone)
head = ht_insert(head, name, phone)
print(head)
buckest = ht_insert(buckest, name, phone)
print(buckest)
print('-----------------------------------------------------\n')
print('============= END TESTING =====================\n\n')
""" Name.append('Masha')
print('============== TESTING HT_FIND =====================')
Name.append('Masha')
for i in range(len(Name)):
name = Name[i]
print(name, ":", ht_find(head, name))
print(name, ":", ht_find(buckest, name))
print("======== END TESTING =============\n\n")
"""
print("================ TESTING TH_LIST_ALL ====================")
print(*ht_list_all(buckest))
print()
#################################################################################################
def main():