1 / 8

Linked Node Problem: Transforming a Picture with Statement Lists

This problem involves transforming a picture with statement lists to form a different picture with list1 and list2. It also explores the number of ListNode variables and which variables change. The text is in English.

mcgahey
Télécharger la présentation

Linked Node Problem: Transforming a Picture with Statement Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linked node problem 3 • What set of statements turns this picture: • Into this? list1 list2 list1 list2

  2. Linked node problem 3 • How many ListNode variables? • Which variables change? C B list1 A E F list2 D C E list1 list2 D

  3. list1 current

  4. Abstract data types (ADTs) • abstract data type (ADT): A specification of a collection of data and the operations that can be performed on it. • Describes what a collection does, not how it does it • Java's collection framework describes several ADTs: • Queue, List, Collection, Deque, List, Map, Set • An ADT can be implemented in multiple ways: • ArrayList and LinkedList implement List • HashSet and TreeSet implement Set • LinkedList, ArrayDeque, etc. implement Queue • The same external behavior can be implemented in many different ways, each with pros and cons.

  5. Similar to array code: int[] a = ...; int i = 0; while (i < a.length) { System.out.println(a[i]); i++; } Linked List vs. Array • Print list values: ListNode list= ...; ListNode current = list; while (current != null) { System.out.println(current.data); current = current.next; }

  6. Before/After • Before • After front front

  7. changing a list • There are only two ways to change a linked list: • Change the value of front (modify the front of the list) • Change the value of <node>.next (modify middle or end of list to point somewhere else) • Implications: • To add in the middle, need a reference to the previous node • Front is often a special case

More Related