-
Notifications
You must be signed in to change notification settings - Fork 248
Convert to Linked List
Sar Champagne Bielert edited this page Apr 20, 2024
·
1 revision
Unit 5 Session 2 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- How are elements added to a linked list?
- Each node in a linked list points to the next node through a reference called
next
.
- Each node in a linked list points to the next node through a reference called
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Create two nodes representing the values "Jigglypuff" and "Wigglytuff" and link them together to form a simple linked list.
1) Instantiate a node with the value "Jigglypuff" and store it in `jigglypuff`.
2) Instantiate another node with the value "Wigglytuff" and store it in `wigglytuff`.
3) Set the `next` attribute of `jigglypuff` to point to `wigglytuff`, creating a link between them.
- Forgetting to link the nodes by not setting the
next
attribute. - Misunderstanding the sequence of the list and linking nodes in the wrong orde
jigglypuff = Node("Jigglypuff")
wigglytuff = Node("Wigglytuff")
jigglypuff.next = wigglytuff