forked from UNN/2026-rff_mp
61 lines
1.3 KiB
Python
61 lines
1.3 KiB
Python
import random
|
|
import time
|
|
import csv
|
|
import sys
|
|
|
|
sys.setrecursionlimit(20000)
|
|
|
|
def ll_insert(head, name, phone):
|
|
data = {'name': name, 'phone': phone, "next": None}
|
|
|
|
if head is None:
|
|
return data
|
|
|
|
current = head
|
|
while current:
|
|
if current['name'] == name:
|
|
current['phone'] = phone
|
|
return head
|
|
if current['next'] is None:
|
|
last = current
|
|
current = current['next']
|
|
|
|
last['next'] = data
|
|
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']
|
|
|
|
prev = head
|
|
current = head['next']
|
|
while current:
|
|
if current['name'] == name:
|
|
prev['next'] = current['next']
|
|
return head
|
|
prev = current
|
|
current = current['next']
|
|
return head
|
|
|
|
|
|
def ll_list_all(head):
|
|
data_list = []
|
|
current = head
|
|
while current:
|
|
data_list.append({'name': current['name'], 'phone': current['phone']})
|
|
current = current['next']
|
|
data_list.sort(key=lambda x: x['name'])
|
|
return data_list |