Skip to content

Latest commit

 

History

History
46 lines (28 loc) · 1.87 KB

File metadata and controls

46 lines (28 loc) · 1.87 KB

Linked List Insertions

append

  • arguments: new value
  • adds a new node with the given value to the end of the list

insert before

  • arguments: value, new value
  • adds a new node with the given new value immediately before the first node that has the value specified

insert after

  • arguments: value, new value
  • adds a new node with the given new value immediately after the first node that has the value specified

TargetError Class

  • if there is no node to insert before or after, raise an error that says there is no targeted node listed, or the node is missing
  • if there is a node in the list, but not the node being named in the arguments, raise this error to indicate that the node given in arguments is not in the linked list or is a missing node
  • if the list is empty, raise this error

Whiteboard Process

Code Challenge 6: Figjam image, link below

Figjam Link-- to navigate the image embedded above

Approach & Efficiency

For all methods, the time big O for these is the length of the linked list that you must traverse to find the target node, or the last node of the list, so : O(n), where n is the length of the linked list. The space is still O(n), since all the nodes still exist in memory, but that memory is dynamic, so it need not take up a larger chunk of memory at once.

Solution

Terminal command: python3 linked_list_insertions.py

Terminal command: python3 -m pytest linked_list_insertions/

Code Links

Insertions