diff --git a/konnovaea/experiments.py b/konnovaea/experiments.py new file mode 100644 index 0000000..e69de29 diff --git a/konnovaea/phonebook.py b/konnovaea/phonebook.py index 6a02ec7..1204fb7 100644 --- a/konnovaea/phonebook.py +++ b/konnovaea/phonebook.py @@ -1,13 +1,16 @@ def ll_insert(head, name, phone): - current = head - while current is not None: - if current['name'] == name: - current['phone'] = phone - return head - current = current['next'] + + new_node = {'name': name, 'phone': phone, 'next': None} - new_node = {'name': name, 'phone': phone, 'next': head} - return new_node + if head is None: + return new_node + + current = head + while current['next'] is not None: + current = current['next'] + + current['next'] = new_node + return head def ll_find(head, name): current = head @@ -25,7 +28,7 @@ def ll_delete(head, name): current = head while current['next'] is not None: if current['next']['name'] == name: - current['next'] = current['naext']['next'] + current['next'] = current['next']['next'] return head current = current['next'] return head @@ -35,7 +38,7 @@ def ll_list_all(head): current = head while current is not None: - records.append((current['name'], current['phine'])) + records.append((current['name'], current['phone'])) current = current['next'] records.sort(key=lambda x: x[0]) return records