[1] add LinkList
This commit is contained in:
parent
34872ab84e
commit
2b8170c6c8
26
pomelovsd/LinkedList
Normal file
26
pomelovsd/LinkedList
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
def create_node(name, phone):
|
||||||
|
return {"name": name, "phone": phone, "next": None}
|
||||||
|
def ll_insert(head, name, phone):
|
||||||
|
node = create_node(name, phone)
|
||||||
|
# Случай для пустого списка
|
||||||
|
if head is None:
|
||||||
|
return node
|
||||||
|
# Случай если надо перезаписать имя
|
||||||
|
current = head
|
||||||
|
while current:
|
||||||
|
if current["name"] == name:
|
||||||
|
current["phone"] = phone
|
||||||
|
return head
|
||||||
|
current = current["next"]
|
||||||
|
# Случай добавления нового элемента
|
||||||
|
current = head
|
||||||
|
while current["next"]:
|
||||||
|
current = current["next"]
|
||||||
|
current["head"] = "node"
|
||||||
|
def ll_find(head, name):
|
||||||
|
current = head
|
||||||
|
while current:
|
||||||
|
if current["name"] == name:
|
||||||
|
return current["phone"]
|
||||||
|
current = current["next"]
|
||||||
|
return None
|
||||||
43
pomelovsd/data_structures.ipynb
Normal file
43
pomelovsd/data_structures.ipynb
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "c533959c",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"a\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.12.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user