Tutorial 4 Linked List, Stack, & Queue

Linked List: Revision Done Last Week« ‡ ‡ The concept of ADT List ADT List using Array ± Pro & cons Discussed in T02Q3 and today in Q1! Basic idea: Slide 17 Item/Value/Content See T03Sup1&2 Pointers to immediate neighbors The basic. ExtendedLinkedList (Slide 29-36) ‡ ‡ Linked List Variations: Linked List with Tail Pointer ± ± ± Can visit the tail very fast Cannot delete the tail easily« In lecture notes (Slide 48-53): TailedLinkedList (revisited in Queue data structure later) Two pointers: forward/backward Can go backwards. Head = Tail.Next Can visit all node from any node . Can delete tail! Extra pointer is overhead In lecture notes (Slide 54-58): DoublyLinkedList Remember Tail only. Good for Round Robin stuffs ‡ ‡ ADT List using Linked List ± ± ± Linked List Node has 2 parts: ‡ Bidirectional Linked List ± ± ± ± ‡ Single Linked List ± ± ± ‡ Circular Linked List ± ± ± ‡ Generic Java (Slide 37-46) for our custom Basic and Extended LinkedList ‡ Generic LinkedList<E> (slide 61-66) for a ³bug-free´. ³ready-to-use´ LL . traversal: head to tail Usually: insert from head ( Stack) In your lecture notes: BasicLinkList (Slide 26-28).

2. 2. 3. 3.Student Presentation ‡ T3 1. N/A N/A N/A ‡ T4 1. 2. Koh Xianghua. Kuganeswari D/O Kuhanesan Chow Jian Ann Chow Jian Ann This week marks the end of this bidding system« Some students have not participate at all! 3 . 3. Tan Miang Yeow (Done Last Week) N/A Chua Kien Chuan Chris ‡ T6 1. 2. Nicholas N/A Sean Lim Wei Xinq ‡ T5 1. 3.

Question 1 (MovieDataAnalysis) ‡ Insert New Item (Movie ADT) to LinkedList ± Ensure that you check for duplicate data! 4 .

‡ Methods ± 1: Scan and select the appropriate movies ± 2: Copy the list and delete movies that are out of range ‡ What if we use Doubly Linked List? ‡ Pro and Cons? 2008 2007 2007 2008 2006 5 .Question 2 (MovieDataAnalysis) ‡ Given time period (yearA ± yearB) ± Get movies that are produced within that range.

perform: ± Intersection ± Union ± Difference ‡ Remember that A-B is not the same as B-A! Person A¶s preference: Person B¶s preference: 6 .Question 3 (MovieDataAnalysis) ‡ Given two TopList containing movies.

Tutorial 5 Preview .

edu/~box/ds/Stack/Stack.Stack ‡ Stack: Last In First Out (LIFO) ‡ Stack Implemented using Array with top pointer ± http://www2.cosc.nz/people/mukundan/dsal/LinkListAppl.latech.html ‡ Best Implementation? ± Using Single Link List with head pointer. demo: ± http://www.html .ac.canterbury.

edu/~streinu/Teaching/Courses/112/Applets/Queue/myApplet.next« .Queue ‡ First In First Out (FIFO) ‡ Queue implemented as Circular Array ± http://maven.smith.html ‡ Queue implemented as Single Link List with Tail Pointer ± Head pointer for dequeue ± Tail pointer for enqueue ± We reverse their role because of the pointer directions ‡ Best Implementation? ± Use Circular Single Link List ± Save one more pointer as head = tail.

Joyeeta Biswas Teo Sim Yee Stephanie Wu Shujun Liu Na Backup Ong Kian An Tan Yan Hao Wang Ruohan Zheng Yang ‡ T4 Main 1. Cai Jingfang Li Huan Zhang Jianfei Tanvir Islam Backup Chng Jiajie Nur Liyana Bte Roslie Tan Kar Ann Jessica Chin Zet Sze ‡ T5 Main 1. Zhang Chao Chua Yu Tong Laura Koh Yi Ting Brenda Siddhartha Backup Wang Shuling Rasheilla Bte Rajah Low Wei Chen Gerard J Gan Zhi Wei James Since some students still have not tried at all Therefore. 2. J Goh Khoon Hiang Hanyenkno Afi Ng Xue Lin Sherilyn Backup Liew Hui Sun Li Yawen Tan Peck Luan Wong Suet Teng. 4. you have 1 week recess!) 10 . 3. 4. Melissa ‡ T6 Main 1. I have to assign 4 random students to do tutorial 5 (Please just treat this as mid-test preparation. Choy Qian Ning. 4. 3.Student Presentation ‡ T3 Main 1. 2. 2. 2. 3. 3. 4.

Question 1 (Applications) ‡ Show us 7 applications of Stacks ‡ Show us 7 applications of Queues 11 .

pop. top/seek Hint: Try the sample input-output manually! Derive patterns and write your algorithm! 12 .Question 2 (Stack: Reorder) ‡ ‡ ‡ ‡ Algorithm to reorder items using one stack! Requires thinking on Stack operations: push.

2.Question 3 (Stack for Sorting) ‡ Find algorithm to sort items using two stacks! ‡ Requires thinking on Stack operations: push. 5} ± {4. 1} {1. 3} {1. 3. 3. 4} ‡ Derive patterns and write your algorithm! 13 . 7} ± {1. top/seek ‡ Hint: try sorting these simple numbers using two stacks: ± {7. 5} {5. 3. 2. 5. pop.

Question 4 (Queue) ‡ What if Queue ADT is implemented using TailedLinkedList but in different way! ‡ Think about the pros and cons of this strategy! 14 .

you have 1 week buffer! ± Recess != holiday!! ‡ However >.Next Week (Recess) ‡ Use your recess week carefully! ± CS1102 midterm test is just RecessWeek.< ± I will be taking my holiday leave« ± Going back to Jakarta 19-25 Sep 08 ± You can email me but my response will be slower« .getNext()! ± For those who are assigned to do Tutorial 5.

Sign up to vote on this title
UsefulNot useful