Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Tutorial 4 – List ADT

2 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 2

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! 3

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 (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: 1.Yan Xun 2.Yong Meng 3.Joseph Ling 4.Min Qi T10: 1.Song Yih 2.Lixun 3.Peidong 4.Muhammad Faizal T13: 1.Jingui 2.Chee Chung 3.Guolong 4.Ee Chan T9: 1.Lam Woon Cherk 2.Mah Chun How 3.Muhammad Daren Meisa 4.Ngoo Cheng Han T17: 1.Claudine 2.Guochen 3.Agrawal 4.Jack 5

6 Q1 – Additional Issues 1.Additional methods, try to implement these: A.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 B.del(idx) It deletes an item at position idx, not just at the back –How will you implement them in IntVector? 2.If your size() is O(n), make it O(1)! –O(n) – one single pass –O(1) – constant step(s)

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

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

9 Q4 – Additional Issues 1.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


Download ppt "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."

Similar presentations


Ads by Google