1 / 15

List ADT

List ADT. Operations Insert into List at front, at end after a specific value, before a specific value Delete from List first value, last value, a specific value Search for a specific value. Implementing a List. Using Vector /Array

urbana
Download Presentation

List ADT

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. List ADT • Operations • Insert into List • at front, at end • after a specific value, before a specific value • Delete from List • first value, last value, a specific value • Search • for a specific value

  2. Implementing a List • Using Vector /Array • requires estimate of maximum list length • may grow dynamically • Ø = empty slots • Can contain varied data/objects (not necessarily homogeneous) L 212 rules! Golf #1 30−0 Ø Ø Ø

  3. Implementing a List • Using Linked List • flexible, adjusts to problem size • implementing a linked list • nodes and references/links/pointers L Ø 212 rules! Golf #1 30−0

  4. Implementing a List 0 1 2 3 4 5 6 7 8 2 -1 7 -1 1 4 3 6 0 Ø • Using Linked List • implementing a linked list • cursor implementation 212 rules! Ø Ø 30−0 L= 5 Golf #1 Free = 8 Ø Ø Ø

  5. Implementing a List • Linked List • types • singly- vs. doubly-linked • linear vs. circular • with vs. without dummy head node • notes • http://www.cs.clemson.edu/~pargas/courses/cs212/common/notes/txt/Lists.txt

  6. Implementing a List Vector/Array Linked List • insertAtFront O(n) O(1) • insertAtEnd O(1) O(1) • insertInMiddle O(n) O(n) • deleteFromFront O(n) O(1) • deleteFromEnd O(1) O(1) • deleteFromMiddle O(n) O(n) • search • linear O(n) << O(n) • binary O(log n) N/A

  7. Doubly Linked ListMethods void insertAtHead (ListNode node) Node removeFromHead() void insertAtTail (ListNode node) Node removeFromTail() void insertAfter(ListNode node, Object obj)

  8. insertAtHead(node)Case 1: empty list head=/ tail=/ // empty list if (head == null) { head = node; tail = node; } node A

  9. insertAtHead(node) Case 1: empty list head tail=/ // empty list if (head == null) { head = node; tail = node; } node A

  10. insertAtHead(node) Case 1: empty list head tail // empty list if (head == null) { head = node; tail = node; } node A

  11. insertAtHead(node)Case 2: non-empty list tail head C B A // non-empty list else { head.setPrev(node); node.setNext(head); head = node; } D node

  12. insertAtHead(node) Case 2: non-empty list tail head C B A // non-empty list else { head.setPrev(node); node.setNext(head); head = node; } D node

  13. insertAtHead(node) Case 2: non-empty list tail head C B A // non-empty list else { head.setPrev(node); node.setNext(head); head = node; } D node

  14. insertAtHead(node) Case 2: non-empty list tail C B A // non-empty list else { head.setPrev(node); node.setNext(head); head = node; } D node head

  15. insertAtHead(node) Case 2: non-empty list tail C B A D head

More Related