1 / 10

Tutorial 4 – List ADT

Tutorial 4 – List ADT. List ADT. List: A collection of homogeneous items ordered in linear fashion, e.g. List of names, phone numbers, integers, etc List ADT An ADT to support such data structure, with some basic operations, e.g. add(idx), get(idx), remove(idx), del_last, size, etc.

galvin
Download Presentation

Tutorial 4 – 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. Tutorial 4 – List ADT

  2. List ADT • List: • A collection of homogeneous itemsordered in linear fashion, e.g. • List of names, phone numbers, integers, etc • List ADT • An ADT to support such data structure,with some basic operations, e.g. • add(idx), get(idx), remove(idx), del_last, size, etc

  3. List ADT Implementation • Basically there are at least two ways: • Use Vector (i.e. array that can resize itself) • Part of the implementation is discussed in Q1 & Q4 • Use Linked List • Discussed in Q3 • In Q2, we uses list ADT, which can be either using vector or linked list!

  4. Linked List: Revision • A Linked List Node has 2 parts: • Item/Value/Content • Pointers to immediate neighbors • Single Linked List • Chain of linked list nodes • Traversal: start from head to tail • Usually: insert from head (ok for Stack) • There are Linked List Variations • See the right hand side • Best is to use STL <list> (Slide 70-72) • A bug-free, ready-to-use Linked List  • Linked List with Tail Pointer • Can visit the tail very fast  • Cannot delete the tail easily…  • In lecture note: not highlighted(revisited in Queue data structure later) • Double Linked List (Slide 46-56) • Two pointers: forward/backward • Can go backwards • Can delete tail easily!  • Extra pointer = more overhead  • Circular Linked List (Slide 57-60) • Remember Tail only, Head = Tail.Next • Can visit all node from any node 

  5. Student Presentation • T5: • Yan Xun • Yong Meng • Joseph Ling • Min Qi • T10: • Song Yih • Lixun • Peidong • Muhammad Faizal • T13: • Jingui • Chee Chung • Guolong • Ee Chan • T9: • Lam Woon Cherk • Mah Chun How • Muhammad Daren Meisa • Ngoo Cheng Han • T17: • Claudine • Guochen • Agrawal • Jack

  6. Q1 – Additional Issues • Additional methods, try to implement these: • add(idx, i) • This is an overloaded methods: same name as add(i) • It adds integer i in position idx, not just at the back • del(idx) • It deletes an item at position idx, not just at the back • How will you implement them in IntVector? • If your size() is O(n), make it O(1)! • O(n) – one single pass • O(1) – constant step(s)

  7. Q2 – Additional Issues • What is the weakness of • addPoint(Point p)? • findNearest(Point refPt, Point& ansPt)?

  8. Q3 – Additional Issues • A “better” Linked List • How to access last node in O(1)? • How to insert item after last node in O(1)? • How to delete last node in O(1)?

  9. Q4 – Additional Issues • How to know the runtime details of the methods in STL?

  10. Next Week • ThisWeek.Next is recess week • Use your recess week carefully! • Revise up to Stack/Queue • We will discuss stack/queue in Tutorial 5 • CS1102C midterm test is ThisWeek.Next.Next • Main topic will be List ADT (vector/linked list)and Stack/Queue • Although C++ is not the main topic, it is usually asked as part of the solution • e.g. write C++ code to modify this Linked List, etc

More Related