SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding Stacks and Queues: Concepts, Implementations, and Applications

eve-vinson avatar
10 diapositives · 260 Views · Nov 13, 2014

This tutorial delves into the core concepts of stacks and queues, exploring their implementations using arrays and linked lists. We discuss the Last In First Out (LIFO) principle of stacks, providing examples and links to resources for further learning. We also cover the First In First Out (FIFO) principle of queues, detailing circular array implementations and linked list strategies. Special focus is given to practical applications, algorithms for sorting with stacks, and innovative ways to implement queues. Ideal for students and enthusiasts of data structures.

Understanding Stacks and Queues: Concepts, Implementations, and Applications - slide 1
01 / 10Understanding Stacks and Queues: Concepts, Implementations, and Applications
1 / 17

Télécharger la présentation

Understanding Stacks and Queues: Concepts, Implementations, and Applications
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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/dsal/LinkListAppl.html TOP

  3. Queue • First In First Out (FIFO) • Queue implemented as Circular Array • http://maven.smith.edu/~streinu/Teaching/Courses/112/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 • CaiJingfangChngJiajie, Colin Tan • Li HuanNurLiyanaBteRoslie • Zhang JianfeiTan Kar Ann • Tanvir Islam Jessica Chin ZetSze • T4 Main Backup • Choy QianNing, JLiewHui Sun • GohKhoonHiang Li Yawen • HanyenknoAfi Tan Peck Luan • Ng Xue Lin SherilynWong Suet Teng, Melissa • T5 Main Backup • JoyeetaBiswasOngKian An • TeoSim Yee Stephanie Tan Yan Hao • Wu Shujun Wang Ruohan • Liu Na Zheng Yang • T6 Main Backup • Zhang Chao Wang Shuling • Chua Yu Tong LauraRasheillaBte Rajah • Koh Yi Ting Brenda Low Wei Chen Gerard J • SiddharthaGanZhi 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 week’s 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…