
Summer 2023 Linked Nodes and List Operations
Explore the linked nodes with loops, agenda reviews, and modifying list node sequences in Summer 2023 lessons. Learn how to print sequences of data and navigate through non-contiguous memory structures. Dive into pseudocode for printing sequences effectively.
Uploaded on | 1 Views
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Linked Nodes w/ Loops Hitesh Boinpally Summer 2023
Agenda Linked Nodes review Traversing ListNode sequences Modifying ListNode sequences Reminders Lesson 3 - Summer 2023 2
Agenda Linked Nodes review Traversing ListNode sequences Modifying ListNode sequences Reminders Lesson 3 - Summer 2023 3
Linked Nodes Review New data structure to represent non-contiguous memory Building blocks for Linked Lists Legos Today: arbitrary length sequences Lesson 3 - Summer 2023 4
Problems so far What statements turn this picture: data next data next data next list1 10 20 40 data next list2 30 Into this picture? (1 Possible) Answer: data next data next list1 ListNode temp = list1.next; list1.next = list1.next.next; temp.next = list2; list2 = temp; 10 40 data next data next list2 Lesson 2 - Summer 2023 30 20 Lesson 3 - Summer 2023 5
Agenda Linked Nodes review Traversing ListNode sequences Modifying ListNode sequences Reminders Lesson 3 - Summer 2023 6
Printing a Sequence data next data next data next list 10 20 800 Suppose we have a sequence of nodes like the above With unknown number of elements How would we print all the values out? Lesson 3 - Summer 2023 7
Printing a Sequence Pseudocode: 8 Lesson 3 - Summer 2023
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node Lesson 3 - Summer 2023 9
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node Console: How to go to the next node? list = list.next; list data next data next data next 10 20 800 Lesson 3 - Summer 2023 10
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node Console: 10 How to go to the next node? list = list.next; list data next data next data next 10 20 800 Lesson 3 - Summer 2023 11
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node Console: 10 20 How to go to the next node? list = list.next; list data next data next data next 10 20 800 Lesson 3 - Summer 2023 12
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node Console: 10 20 800 How to go to the next node? list = list.next; list data next data next data next 10 20 800 Lesson 3 - Summer 2023 13
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node Console: 10 20 800 How to go to the next node? list = list.next; list data next data next data next 10 20 800 Lesson 3 - Summer 2023 14
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node Console: 10 20 800 How to go to the next node? list = list.next; Destroys the list! list data next data next data next 10 20 800 Lesson 3 - Summer 2023 15
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node How to go to the next node? Create a new variable and change it ListNode current = list current = current.next Console: data next data next data next list 10 20 800 16 Lesson 3 - Summer 2023
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node How to go to the next node? Create a new variable and change it ListNode current = list current = current.next Console: current data next data next data next list 10 20 800 Lesson 3 - Summer 2023 17
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node How to go to the next node? Create a new variable and change it ListNode current = list current = current.next Console: 10 current data next data next data next list 10 20 800 Lesson 3 - Summer 2023 18
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node How to go to the next node? Create a new variable and change it ListNode current = list current = current.next Console: 10 20 current data next data next data next list 10 20 800 Lesson 3 - Summer 2023 19
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node How to go to the next node? Create a new variable and change it ListNode current = list current = current.next Console: 10 20 800 current data next data next data next list 10 20 800 Lesson 3 - Summer 2023 20
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node How to go to the next node? Create a new variable and change it ListNode current = list current = current.next Console: 10 20 800 current data next data next data next list 10 20 800 Lesson 3 - Summer 2023 21
Printing a Sequence Pseudocode: Start at the front of the list While there are nodes to print: Print the current node s data Go to the next node How to go to the next node? list = list.next; Destroys the list! ListNode current = list current = current.next Console: 10 20 800 List is still intact! current data next data next data next list 10 20 800 Lesson 3 - Summer 2023 22
Agenda Linked Nodes review Traversing ListNode sequences Modifying ListNode sequences Reminders Lesson 3 - Summer 2023 23
slido.com code: #su_cse123 Adding to a Sequence Suppose we had the following sequence: data next data next data next list1 1 2 3 What happens when we execute the below code? Lesson 3 - Summer 2023 24
Agenda Linked Nodes review Traversing ListNode sequences Modifying ListNode sequences Reminders Lesson 3 - Summer 2023 25
Reminders First resubmission form released tomorrow Due next Friday Can only resubmit assignments we have given feedback on! No section on Tuesday We will still post materials Optional like always Lesson 3 - Summer 2023 26