forked from UNN/2026-rff_mp
[16] adding plt
This commit is contained in:
parent
17d62ab5ad
commit
d71c9d311e
|
|
@ -1,6 +1,7 @@
|
|||
import random as rnd
|
||||
import time
|
||||
import csv
|
||||
import matplotlib.pyplot as plt
|
||||
#############################################################################################
|
||||
|
||||
def sort_list(name_list):
|
||||
|
|
@ -24,6 +25,17 @@ def file_insert(results):
|
|||
with open("results.csv", "w", encoding = "utf-8-sig", newline = "") as file:
|
||||
writer = csv.writer(file)
|
||||
writer.writerows(results)
|
||||
|
||||
def drow(time, color_fun):
|
||||
x = []
|
||||
y = []
|
||||
for key in time:
|
||||
x.append(key)
|
||||
y.append(time[key] * 1000)
|
||||
plt.plot(x, y, marker = ".", color = color_fun, markersize = 2, alpha = 0.9)
|
||||
|
||||
|
||||
|
||||
###########################################################################################################################
|
||||
|
||||
def ll_insert(head, name, phone):
|
||||
|
|
@ -122,7 +134,7 @@ def LinkedList(head, phone_book):
|
|||
#########################################################################################################
|
||||
|
||||
def ht_insert(buckest, name, phone):
|
||||
index = hash_key(name) % 10
|
||||
index = hash_key(name) % len(buckest)
|
||||
for i, (Name, Phone) in enumerate(buckest[index]):
|
||||
if Name == name:
|
||||
buckest[index][i] = (name, phone)
|
||||
|
|
@ -131,7 +143,7 @@ def ht_insert(buckest, name, phone):
|
|||
return buckest
|
||||
|
||||
def ht_find(buckest, name):
|
||||
index = hash_key(name) % 10
|
||||
index = hash_key(name) % len(buckest)
|
||||
for (Name, Phone) in buckest[index]:
|
||||
if Name == name:
|
||||
return Phone
|
||||
|
|
@ -151,7 +163,7 @@ def ht_list_all(buckest):
|
|||
|
||||
|
||||
def ht_delete(buckest, name):
|
||||
index = hash_key(name) % 10
|
||||
index = hash_key(name) % len(buckest)
|
||||
for i, (Name, Phone) in enumerate(buckest[index]):
|
||||
if Name == name:
|
||||
del buckest[index][i]
|
||||
|
|
@ -331,7 +343,7 @@ def main():
|
|||
|
||||
phone_book_sorted = phone_book.copy()
|
||||
phone_book_sorted = sort_list(phone_book_sorted)
|
||||
replay = 5
|
||||
replay = 10
|
||||
|
||||
|
||||
Time_ll_not_sorted = []
|
||||
|
|
@ -458,6 +470,26 @@ def main():
|
|||
results[i][3] *= 1000
|
||||
file_insert(results)
|
||||
|
||||
plt.figure(figsize = (16, 9))
|
||||
plt.xlabel("Операция")
|
||||
plt.ylabel("Время мс")
|
||||
|
||||
drow(Time_average_ll_not_sorted, "blue")
|
||||
drow(Time_average_ll_sorted, "green")
|
||||
drow(Time_average_ht_not_sorted, "#FF8800")
|
||||
drow(Time_average_ht_sorted, "#FF0000")
|
||||
drow(Time_average_bst_not_sorted, "#464219")
|
||||
drow(Time_average_bst_sorted, "#FBFF00")
|
||||
|
||||
text = """
|
||||
синий - LinkedList (not sorted) ораньжевый - HashTable (not sorted) коричневый - BST (not sorted)
|
||||
зеленый - LinkedList (sorted) красный - HashTable (sorted) желтый - BST (sorted)
|
||||
"""
|
||||
# plt.subplots_adjust(bottom =0.3)
|
||||
plt.figtext(0.1, 0.02, text, wrap = True, fontsize = 9, va = 'bottom')
|
||||
plt.savefig("time_schedule.png")
|
||||
plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user