Data Structures & Algorithms

Slides:



Advertisements
Similar presentations
CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
Advertisements

CS Data Structures II Review COSC 2006 April 14, 2017
Chapter 3: Abstract Data Types Lists, Stacks Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Stacks A stack is a data structure that only allows items to be inserted and removed at one end We call this end the top of the stack The other end is.
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Lecture 6 Feb 12 Goals: stacks Implementation of stack applications Postfix expression evaluation Convert infix to postfix.
Stacks.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
Chapter 18: Stacks and Queues
1 Lecture 26 Abstract Data Types – IV Overview  The List ADT  Implementing Stacks as Linked List  Linked List Implementation of Queues .  Preview:
Lists CSE1303 Part A Data Structures and Algorithms.
CHAPTER 3 : STACKS 3.1 Understand Stacks 3.2 Implement the operation of stack By : Suzila Yusof.
Chapter 17: Stacks and Queues
Objectives of these slides:
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks.
Topic 3 The Stack ADT.
Ceng-112 Data Structures ITurgut Kalfaoglu 1 Chapter 3 Stacks.
Chapter 7 Stacks Dr. Youssef Harrath
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
Chapter 4 Stacks Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving. Its called.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Stacks and Queues Introduction to Computing Science and Programming I.
SAK 3117 Data Structures Chapter 3: STACKS. Objective To introduce: Stack concepts Stack operations Stack applications CONTENT 3.1 Introduction 3.2 Stack.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
DATA STRUCTURE & ALGORITHMS CHAPTER 3: STACKS. 2 Objectives In this chapter, you will: Learn about stacks Examine various stack operations Discover stack.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
Chapter 18: Stacks and Queues
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 3.
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
1 CS 132 Spring 2008 Chapter 7 Stacks Read p Problems 1-7.
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues (part 2)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 2)
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Data Structures Using C++1 Chapter 7 Stacks. Data Structures Using C++2 Chapter Objectives Learn about stacks Examine various stack operations Learn how.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Data Structures Using Java1 Chapter 6 Stacks. Data Structures Using Java2 Chapter Objectives Learn about stacks Examine various stack operations Learn.
1 Chapter 17: Stacks and Queues Learn about stacks Examine various stack operations Learn how to implement a stack as an array Learn how to implement a.
Chapter 17: Stacks and Queues. Objectives In this chapter, you will: – Learn about stacks – Examine various stack operations – Learn how to implement.
Computer Engineering Rabie A. Ramadan Lecture 6.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Data Structures Using C++ 2E
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Stacks and Queues Chapter 4.
Chapter 15 Lists Objectives
Hassan Khosravi / Geoffrey Tien
Stacks and Queues.
Cinda Heeren / Geoffrey Tien
Stack and Queue APURBO DATTA.
Building Java Programs
Principles of Computing – UFCFA3-30-1
Pointers and Linked Lists
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Data Structures and Database Applications Stacks in C#
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Stacks Data structure Elements added, removed from one end only
Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 7 © 2011 Pearson Addison-Wesley. All rights reserved.
Stack Implementations
Presentation transcript:

Data Structures & Algorithms CHAPTER 6 Stacks Ms. Manal Al-Asmari

Stacks and Queues Define two new abstract data types *Both are restricted lists *Can be implemented using arrays or linked lists Stacks “Last In First Out” (LIFO) The last element inserted will be the first to be retrieved Queues “First In First Out” (FIFO) Ms. Manal Al-Asmari

Stack Overview Stack ADT Basic operations of stack *Pushing, popping etc. Implementations of stacks using *array *linked list Ms. Manal Al-Asmari

Stack ADT A stack is a list of the same kind of elements with the restriction that insertions and deletions can only be performed at the top of the list. The other end is called bottom Ms. Manal Al-Asmari

The Stack ADT Stack applications can be classified into four broad categories: reversing data, pairing data, postponing data usage backtracking steps Ms. Manal Al-Asmari

Conceptual Stacks Ms. Manal Al-Asmari

Stacks Stacks are also called Last Input First Output (LIFO) data structures. Operations performed on stacks: Push: Equivalent to insert Pop: Deletes the most recently inserted element Peek: Examines the most recently inserted element Ms. Manal Al-Asmari

Stack Operations Ms. Manal Al-Asmari

Push and Pop Primary operations: Push and Pop Push Add an element to the top of the stack B. Pop Remove the element at the top of the stack Ms. Manal Al-Asmari

Stacks implementation Any list implementation can be used to implement a stack Arrays (static: the size of stack is given initially) Linked lists (dynamic: never become full) Ms. Manal Al-Asmari

Implementation of Stacks as Arrays The array implementing a stack is an array of reference variables Each element of the stack can be assigned to an array slot The top of the stack is the index of the last element added to the stack To keep track of the top position, declare a variable called stackTop Ms. Manal Al-Asmari

Implementation of Stacks as Arrays Ms. Manal Al-Asmari

Constructors Default constructor Ms. Manal Al-Asmari

Initialize Stack Method initializeStack: Ms. Manal Al-Asmari

Empty Stack Method isEmptyStack: Ms. Manal Al-Asmari

Full Stack Method isFullStack: Ms. Manal Al-Asmari

Push Method push: Ms. Manal Al-Asmari

Peek Method peek: Ms. Manal Al-Asmari

Pop Method pop: Ms. Manal Al-Asmari

THE END Ms. Manal Al-Asmari