1 / 10

Tutorial 3 - Linked List

Tutorial 3 - Linked List. Linked List: Revision. Reserved for next week…. The concept of ADT List ADT List using Array Pro & cons  Discussed in T02Q3 and today in Q1! ADT List using Linked List Basic idea: Slide 17 Linked List Node has 2 parts: Item/Value/Content  See T03Sup1&2

carlos-wolf
Download Presentation

Tutorial 3 - Linked List

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. Tutorial 3 - Linked List

  2. Linked List: Revision Reserved for next week… • The concept of ADT List • ADT List using Array • Pro & cons  Discussed in T02Q3and today in Q1! • ADT List using Linked List • Basic idea: Slide 17 • Linked List Node has 2 parts: • Item/Value/Content  See T03Sup1&2 • Pointers to immediate neighbors • Single Linked List • The basic; traversal: head to tail • Usually: insert from head (ok for Stack) • In your lecture notes: BasicLinkList (Slide 26-28), ExtendedLinkedList (Slide 29-36) • Generic Java (Slide 37-46) for our custom Basic and Extended LinkedList • Linked List Variations: • Linked List with Tail Pointer • Can visit the tail very fast  • Cannot delete the tail easily…  • In lecture notes (Slide 48-53): TailedLinkedList(revisited in Queue data structure later) • Bidirectional Linked List • Two pointers: forward/backward • Can go backwards, Can delete tail!  • Extra pointer is overhead  • In lecture notes (Slide 54-58):DoublyLinkedList • Circular Linked List • Remember Tail only, Head = Tail.Next • Can visit all node from any node . • Generic LinkedList<E> (slide 61-66) for a “bug-free”, “ready-to-use” LL 

  3. Student Presentation • T3 Sup1. Ng Hong Geh Sup2. N/A • KohXianghua, Nicholas (deferred until next week) • N/A • N/A • SeoJia Wei David • T4 Sup1. Chong TzeKoi Sup2. Chong TzeKoi • Tan MiangYeow • N/A • N/A • N/A • T5 Sup1. Wang Ruohan Sup2. Zhang Denan, Zhang Yang • N/A • N/A • N/A • N/A • T6 Sup1. N/A Sup2. N/A • Kuganeswari D/O Kuhanesan (deferred until next week) • N/A • N/A • KohJyeYiing Hm… not that good… Anyone wants to take Sup1 & Sup2 questions?

  4. Question Supplementary 1 ListNode First = new ListNode(“first”); ListNode Last = First; ListNode Temp; for (int j = 1; j < 6; j++) if (j % 2 == 0) { Temp = new ListNode(“j = “ + j); Last.next = Temp; Last = Temp; } else First = new ListNode(“j = “ + j, First); Trace this!

  5. Question Supplementary 2 Now, rearrange: J=5  J=3  J=1  first  J=2  J=4 into first  J=1  J=2  J=3  J=4  J=5

  6. Question 1 (MovieDataAnalysis) • (Prologue) Array Based ADT (Lect 3, Slide 6-15) • Pros? • Cons? • Real question: Insert New Item (Movie ADT) to LinkedList • Ensure that you check for duplicate data!

  7. Question 2 (MovieDataAnalysis) • Given time period (yearA – yearB) • Get movies that are produced within that range. • Methods • 1: Scan and select the appropriate movies • 2: Copy the list and delete movies that are out of range • What if we use Doubly Linked List? • Pro and Cons? 2008 2007 2007 2008 2006

  8. Question 3 (MovieDataAnalysis) • Given two TopList containing movies, perform: • Intersection • Union • Difference • Remember that A-B is not the same as B-A! Person A’s preference: Person B’s preference:

  9. Question 4 (Guess Output) • ExtendedLinkedList list = new ExtendedLinkedList();list.addHead(“ZZZ”); list.addHead(“YYY”); list.addHead(“XXX”);list.addHead(“WWW”); list.addHead(“VVV”); • A: ListNode node = list.getHeadPtr(); printList(node); • VVV, WWW, XXX, YYY, ZZZ • B: System.out.println(node.next.next.next); • YYY • C: node = node.next(), printList(node); • WWW, XXX, YYY, ZZZ • D: node = list.getHeadPtr(); list.deleteAfter(node); printList(node); • VVV, XXX, YYY, ZZZ • E: ListNode fNode = new ListNode(“FFF”, node); node.next = fNode;printList(node); • VVV, FFF, VVV, FFF, … (infinite)

  10. Next Week • Revisit the leftover materials from today’s tutorial • Revise stack/queue • ThisWeek.Next.Next is recess week • Use your recess week carefully! • CS1102 midterm test is just one week after it!

More Related