1 / 23

Question of the Day

Question of the Day.

happy
Télécharger la présentation

Question of the Day

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. Question of the Day • Two friends were talking when the first said he could hold his breath for 6 minutes under water. The second replied:So. I can stay under water for 10 minutes without any equipment at all.After agreeing upon a $10,000 wager, the second friend won the bet and even went for 30 minutes. How?

  2. Question of the Day • Two friends were talking when the first said he could hold his breath for 6 minutes under water. The second replied:So. I can stay under water for 10 minutes without any equipment at all.After agreeing upon a $10,000 wager, the second friend won the bet and even went for 30 minutes. How? She filled a glass with water & held it over her head!

  3. Lecture 19:TRAVERSING A LIST & More Linked-lists

  4. Singly Linked List SLinkedList head size  4 Node Node Node Node elem next elem next elem next elem next • Are created using linear sequence of nodes • Each Node contains: • Reference to data (element)stored in Node • Link to next Node in linked list

  5. Nodes Are Not Enough • Nodes are workers making linked lists possible • Necessary for the smooth running of linked list • Treated like other jobs smoothing things out • Added & removed as needed • Used only to keep the list running

  6. Nodes Are Not Enough

  7. Nodes Are Not Enough

  8. Nodes Are Not Enough • Nodes are workers making linked lists possible • Necessary for the smooth running of linked list • Treated like other jobs smoothing things out • Added & removed as needed • Used only to keep the list running • Never allowed outside of the linked list

  9. Nodes Are Not Enough • Nodes are workers making linked lists possible • Necessary for the smooth running of linked list • Treated like other jobs smoothing things out • Added & removed as needed • Used only to keep the list running • Never allowed outside of the linked list • Has to wear tie to meet their new boss

  10. T removeFirst()

  11. T removeFirst() head size  4 head size  3

  12. T removeMiddle(Node<T> prev) head size  4 head size  3

  13. Traversing a List • Often need to go through items in a list • Return element stored by the nthNode • Search and find if element is in list • Count elements larger/smaller/equal than some value • Add an element at list’s end • Cannot do this directly with linked lists • Arrays have brackets, but linked lists use objects • Must traverse list by travelling from Node to Node • Relies heavily on understanding how objects work

  14. void addLast(T el) head size  4 head size  5

  15. Doubly Linked List DNode Instance prev elem next • Link to previous node in list also in each node • Each DNode contains: • Element (data) reference • Link to nextDNode • Prev(ious) DNodealso linked

  16. Doubly Linked List Doubly Linked List With 4 Elements • Link to previous node in list also in each node • Each DNode contains: • Element (data) reference • Link to next DNode • Prev(ious) DNodealso linked

  17. Doubly Linked List Sequence of 4 DNodes • Link to previous node in list also in each node • Each DNode contains: • Element (data) reference • Link to next DNode • Prev(ious) DNodealso linked

  18. Doubly Linked List Doubly Linked List With 4 Elements & Sentinels • Link to previous node in list also in each node • Each DNode contains: • Element (data) reference • Link to next DNode • Prev(ious) DNodealso linked

  19. Doubly Linked List DList header trailer size 4 Doubly Linked List With 4 Elements & Sentinels • Link to previous node in list also in each node • Each DNode contains: • Element (data) reference • Link to next DNode • Prev(ious) DNodealso linked

  20. Doubly Linked List • DNodecould extend Node • next & elem fields are needed by both classes • Only difference is prev field added by DNode • DListis not subclass of SList • Both classes define identical methods… • …are entirely different when implemented 1

  21. Circular Linked List head size  4 • Identical nodes as singly or doubly linked list • This example shows singly linked variety • Reference to first node stored in last node • Notice this becomes a big circle • Now you know idea behind name

  22. Your Turn • Get into your groups and complete activity

  23. For Next Lecture • Read GT3.5 for Monday • What is recursion? • Why does recursion rock so much? • How do you write a recursive method? • Week #7 weekly assignment available now • Since no school Tues., assignment due Wednesday • Programming assignment #1 due next Friday • Should be fun to learn about & use encryption • Pulls everything together & sees how much you know

More Related