100 likes | 372 Views
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.
E N D
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
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!
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
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
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)
Q2 – Additional Issues • What is the weakness of • addPoint(Point p)? • findNearest(Point refPt, Point& ansPt)?
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)?
Q4 – Additional Issues • How to know the runtime details of the methods in STL?
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