linked_list
This commit is contained in:
parent
2ce10515cd
commit
2f7370eb01
|
|
@ -1,12 +1,44 @@
|
||||||
|
def ll_create_node(name, phone):
|
||||||
|
return {'name': name, 'phone': phone}
|
||||||
|
|
||||||
def ll_insert(head, name, phone):
|
def ll_insert(head, name, phone):
|
||||||
{'name': name, 'phone': phone}
|
if head is None:
|
||||||
pass
|
return ll_create_node(name, phone)
|
||||||
|
current = head
|
||||||
|
while current:
|
||||||
|
if current ['name'] == name:
|
||||||
|
current['phone'] = phone
|
||||||
|
return head
|
||||||
|
if current ['next'] is None:
|
||||||
|
break
|
||||||
|
current = current['next']
|
||||||
|
current['next'] = ll_create_node(name, phone)
|
||||||
|
return head
|
||||||
|
|
||||||
def ll_find(head, name):
|
def ll_find(head, name):
|
||||||
pass
|
current = head
|
||||||
|
while current:
|
||||||
|
if current['name'] == name:
|
||||||
|
return current['phone']
|
||||||
|
current = current['next']
|
||||||
|
return None
|
||||||
|
|
||||||
def ll_delete(head, name):
|
def ll_delete(head, name):
|
||||||
pass
|
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
|
||||||
|
|
||||||
def ll_list_all(head):
|
def ll_list_all(head):
|
||||||
pass
|
items = []
|
||||||
|
current = head
|
||||||
|
while current:
|
||||||
|
items.append((current['name'], current['phone']))
|
||||||
|
current = current['next']
|
||||||
|
return sorted(items, key=lambda x:x[0])
|
||||||
Loading…
Reference in New Issue
Block a user