forked from UNN/2026-rff_mp
created linked list
созданы функции добавления, удаления, изменения и ввода даынных для связонного списка
This commit is contained in:
parent
58ab8d9227
commit
706e7b5e7f
|
|
@ -0,0 +1,52 @@
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def ll_insert(head, name, phone):
|
||||||
|
curr = head
|
||||||
|
while curr is not None:
|
||||||
|
if curr['name'] == name:
|
||||||
|
curr['phone'] = phone
|
||||||
|
return head
|
||||||
|
curr = curr['next']
|
||||||
|
# Вставка в начало (проще и быстрее)
|
||||||
|
new_node = {'name': name, 'phone': phone, 'next': head}
|
||||||
|
return new_node
|
||||||
|
|
||||||
|
|
||||||
|
def ll_find(head, name):
|
||||||
|
curr = head
|
||||||
|
while curr is not None:
|
||||||
|
if curr['name'] == name:
|
||||||
|
return curr['phone']
|
||||||
|
curr = curr['next']
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def ll_delete(head, name):
|
||||||
|
if head is None:
|
||||||
|
return None
|
||||||
|
if head['name'] == name:
|
||||||
|
return head['next']
|
||||||
|
prev = head
|
||||||
|
curr = head['next']
|
||||||
|
while curr is not None:
|
||||||
|
if curr['name'] == name:
|
||||||
|
prev['next'] = curr['next']
|
||||||
|
return head
|
||||||
|
prev = curr
|
||||||
|
curr = curr['next']
|
||||||
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
def ll_list_all(head):
|
||||||
|
entries = []
|
||||||
|
curr = head
|
||||||
|
while curr is not None:
|
||||||
|
entries.append((curr['name'], curr['phone']))
|
||||||
|
curr = curr['next']
|
||||||
|
entries.sort(key=lambda x: x[0])
|
||||||
|
return entries
|
||||||
Loading…
Reference in New Issue
Block a user