forked from UNN/2026-rff_mp
Связный список
This commit is contained in:
parent
b4daf9ea72
commit
07fe035d63
56
tseremonnikovaaa/task 1/docs/data/main.py
Normal file
56
tseremonnikovaaa/task 1/docs/data/main.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import time
|
||||
import random
|
||||
import csv
|
||||
import sys
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
sys.setrecursionlimit(20000)
|
||||
|
||||
REPEATS = 5
|
||||
N = 10000
|
||||
def ll_insert(head, name, phone):
|
||||
current = head
|
||||
prev = None
|
||||
while current is not None:
|
||||
if current['name'] == name:
|
||||
current['phone'] = phone
|
||||
return head
|
||||
prev = current
|
||||
current = current['next']
|
||||
new_node = {'name': name, 'phone': phone, 'next': None}
|
||||
if prev is None:
|
||||
return new_node
|
||||
else:
|
||||
prev['next'] = new_node
|
||||
return head
|
||||
|
||||
def ll_find(head, name):
|
||||
current = head
|
||||
while current is not None:
|
||||
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'] is not None:
|
||||
if current['next']['name'] == name:
|
||||
current['next'] = current['next']['next']
|
||||
return head
|
||||
current = current['next']
|
||||
return head
|
||||
|
||||
def ll_collect_all(head):
|
||||
records = []
|
||||
current = head
|
||||
while current is not None:
|
||||
records.append((current['name'], current['phone']))
|
||||
current = current['next']
|
||||
records.sort(key=lambda x: x[0])
|
||||
return records
|
||||
Loading…
Reference in New Issue
Block a user