forked from UNN/2026-rff_mp
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
import time
|
|
import random
|
|
import csv
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
def ll_insert(head, name, phone):
|
|
new_node = {'name': name, 'phone': phone, 'next': None}
|
|
if head is None:
|
|
return new_node
|
|
current = head
|
|
while current:
|
|
if current['name'] == name:
|
|
current['phone'] = phone
|
|
return head
|
|
if current['next'] is None:
|
|
current['next'] = new_node
|
|
return head
|
|
current = current['next']
|
|
return head
|
|
|
|
def ll_find(head, name):
|
|
current = head
|
|
while current:
|
|
if current['name'] == name:
|
|
return current['phone']
|
|
current = current['next']
|
|
return None
|
|
|
|
def ll_delete(head, name):
|
|
if head is None:
|
|
return None
|
|
if head['name'] == name:
|
|
return head['next']
|
|
current = head
|
|
while current['next']:
|
|
if current['next']['name'] == name:
|
|
current['next'] = current['next']['next']
|
|
return head
|
|
current = current['next']
|
|
return head
|
|
|
|
def ll_list_all(head):
|
|
records = []
|
|
current = head
|
|
while current:
|
|
records.append((current['name'], current['phone']))
|
|
current = current['next']
|
|
return sorted(records, key=lambda x: x[0]) |