Tutorial 1 C Programming - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Tutorial 1 C Programming

Description:

Stack implemented using Single Link List with head pointer ... implementation to date? http://www.cosc.canterbury.ac.nz/people/mukundan/dsal/LinkListAppl.html ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 11
Provided by: dcsa
Category:

less

Transcript and Presenter's Notes

Title: Tutorial 1 C Programming


1
Tutorial 5Stack Queue, Midtest
2
Stack
  • Last In First Out (LIFO)
  • Stack implemented using Array with top pointer
  • http//www2.latech.edu/box/ds/Stack/Stack.html
  • Stack implemented using Single Link List with
    head pointer
  • Probably the best implementation to date?
  • http//www.cosc.canterbury.ac.nz/people/mukundan/d
    sal/LinkListAppl.html

TOP
3
Queue
  • First In First Out (FIFO)
  • Queue implemented as Circular Array
  • http//maven.smith.edu/streinu/Teaching/Courses/1
    12/Applets/Queue/myApplet.html
  • Queue implemented as Single Link List with Tail
    Pointer
  • Head pointer (easy for insert/delete) for dequeue
  • Tail pointer (only easy for insert) for enqueue
  • This is because of the pointer directions
  • Probably the best implementation to date?

FRONT
BACK
4
Student Presentation
  • T3 Main Backup
  • Cai Jingfang Chng Jiajie, Colin Tan
  • Li Huan Nur Liyana Bte Roslie
  • Zhang Jianfei Tan Kar Ann
  • Tanvir Islam Jessica Chin Zet Sze
  • T4 Main Backup
  • Choy Qian Ning, J Liew Hui Sun
  • Goh Khoon Hiang Li Yawen
  • Hanyenkno Afi Tan Peck Luan
  • Ng Xue Lin Sherilyn Wong Suet Teng, Melissa
  • T5 Main Backup
  • Joyeeta Biswas Ong Kian An
  • Teo Sim Yee Stephanie Tan Yan Hao
  • Wu Shujun Wang Ruohan
  • Liu Na Zheng Yang
  • T6 Main Backup
  • Zhang Chao Wang Shuling
  • Chua Yu Tong Laura Rasheilla Bte Rajah
  • Koh Yi Ting Brenda Low Wei Chen Gerard J
  • Siddhartha Gan Zhi Wei James

Rule Student in Main column has priority to
answer the assigned question If the student
sick/disappear/absent/cannot solve, etc2 the
backup will take over. If both students are
attending the session,I will create variants of
the question for the backup students.
5
Question 1 (Applications)
  • Show us 7 applications of Stacks
  • Show us 7 applications of Queues
  • Be creative!

6
Question 2 (Stack Reorder)
  • Get algorithm to reorder items using one stack!
  • Requires thinking on Stack operations push, pop,
    top/seek
  • Derive patterns!
  • Target Sequence 1 1, 2, 3, 5, 4
  • Target Sequence 2 2, 1, 4, 3, 5
  • Target Sequence 3 5, 2, 4, 3, 1
  • Target Sequence 4 1, 4, 3, 2, 5

Only Target Sequence 3 is impossible. See
StackTest.java for details
7
Question 3 (Stack for Sorting)
  • Find algorithm to sort items using two stacks!
  • Requires thinking on Stack operations push, pop,
    top/seek
  • Hint try sorting these simple numbers using two
    stacks
  • 7, 5 ? 5, 7
  • 1, 5, 3 ? 1, 3, 5
  • 4, 3, 2, 1 ? 1, 2, 3, 4
  • Derive patterns and write your algorithm!
  • Hint During the sorting process, one stack will
    have numbers in ascending order and the other in
    descending order.
  • See StackSort.java for details

8
Question 4 (Queue)
  • What if Queue ADT is implemented using
    TailedLinkedListbut in different way!
  • Think about the pros and cons of this strategy!
  • The ADT Queue dequeue operation is performed by
    delete head and ADT Queue enqueue operation
    is performed by insert from tail in
    TailedLinkedList.
  • Modified operations
  • Enqueue insert from head ? straightforward
  • Dequeue delete from tail ? hard, because
    adjusting tail pointer is difficult!
  • No pro, this modified operations are bad!
  • If you are presented with this kind of question
    during exam, do not hesitate to answer there is
    no pro rather than leaving your answer blank!
  • If you insist, you can say that this modified
    operations can easily tell you what object is
    the 2nd last inserted object

9
Student Presentation for Tut 6
  • Check your email!
  • If I send you an email, it means that you are
    assigned to do next weeks questions

10
Midterm Test Tips
  • Priority
  • Java Revisit low
  • ADT Likely embedded in Linked List/Stack/Queue
    question
  • Linked List we spend two weeks here, most likely
    this appear as the only short question during
    midterm test
  • Stack and Queue definitely appear
  • Try
  • Mixing and matching various data structure
    implementations variant of linked list,
    implementing stacks or queues using funny data
    structures, etc
Write a Comment
User Comments (0)
About PowerShow.com