Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
§3 The Stack ADT 1. ADT A stack is a Last-In-First-Out (LIFO) list, that is, an ordered list in which insertions and deletions are.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
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.
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
Objectives of these slides:
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
Ceng-112 Data Structures ITurgut Kalfaoglu 1 Chapter 3 Stacks.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
DATA STRUCTURE & ALGORITHMS CHAPTER 3: STACKS. 2 Objectives In this chapter, you will: Learn about stacks Examine various stack operations Discover stack.
CHAPTER 3 Lists, Stacks, and Queues §1 Abstract Data Type (ADT) 【 Definition 】 Data Type = { Objects }  { Operations } 〖 Example 〗 int = { 0,  1, 
30 May Stacks (5.1) CSE 2011 Winter Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An.
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)
Linked List by Chapter 5 Linked List by
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
STACKS & QUEUES for CLASS XII ( C++).
Stack: a Linked Implementation
Data Structures Using C++ 2E
Unit – I Lists.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Pointers and Linked Lists
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
Pointers and Linked Lists
Revised based on textbook author’s notes.
MEMORY REPRESENTATION OF STACKS
CS 1114: Implementing Search
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Data Structures and Algorithms
Objectives In this lesson, you will learn to: Define stacks
Stacks and Queues.
Queues Queues Queues.
Cinda Heeren / Geoffrey Tien
Visit for more Learning Resources
Notes on Assignment 1 Your code will have several classes, most notably the class that represents the entire list data structure, and the class.
Abstract Data Types Stack, Queue Amortized analysis
CMSC 341 Lecture 5 Stacks, Queues
Pointers and Linked Lists
Stacks, Queues, and Deques
Stacks Chapter 5 Adapted from Pearson Education, Inc.
STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai.
Chapter 13 Collections.
Stacks, Queues, and Deques
Lesson Objectives Aims
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
CS212D: Data Structures Week 5-6 Linked List.
The List, Stack, and Queue ADTs
Data Structures and Algorithms
Stacks: Implemented using Linked Lists
Abstract Data Types Stack, Queue Amortized analysis
Stacks and Queues 1.
Data Structures and Algorithms for Information Processing
Cs212: Data Structures Computer Science Department Lecture 6: Stacks.
Stacks Chapter 5.
Stacks CS-240 Dick Steflik.
Stacks and Queues CSE 373 Data Structures.
Stacks, Queues, and Deques
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
Abstract Data Types Stacks CSCI 240
LINEAR DATA STRUCTURES
Lecture 9: Stack and Queue
Presentation transcript:

Chapter 3 Lists, Stacks, Queues

Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations that can be performed on the items – Nothing about HOW to do the operations For example add to the end Length of list

C++ Classes and ADT The C++ class facility makes it easy to implement ADTs. – Hides the details from the user – Easy to change the details (would not have to change programs that use the class) – The interface (argument sequence) should never have to change (if it does, then it was a poor design).

List (not linked list) A basic ADT is a List. A list holds a collection of items – Class roll – Shopping list Each item has a position Various operations – Print, makeEmpty, insert, remove, find – Must determine error conditions Remove from empty list, find value not there…

Implementations – Array Very easy to use an array to implement the List ADT. Fixed size Easy to add and remove at the end Easy to find – Very easy to find if list is ordered Easy to go to a specified position (findKth) “Hard” to add and remove from anywhere else – Must move items up or down (think of big lists) NOTE: Easy and hard are computer time, not programmer effort.

Implementation – Linked Lists Easy to add to beginning Can be easy to add to end (if keep an end pointer) Easy to add after/before any position (just change pointers after you get to that position) findKth not as easy as array based Can be done with dynamic memory (no fixed size).

Doubly Linked Lists If we ever need to “back up” in a linked list, it will be very difficult. – Have to start at beginning, keep a previous pointer and go until get to “current” node. Instead, have a node keep a previous (as well as next) link. The first node’s previous will be NULL. More pointers to change when inserting or deleting, but still just a fixed amount of code to execute – O(1). Also makes insertInOrder easier (no need to keep a previous pointer.

Stack Last-in-First-out model. The only real rule is that when we remove from a stack, we get the last thing added (that has not already been removed) – How that is implemented is up to the designer Operations – Push, pop (mandatory) – Nice: top, size, isempty….

Stack Implementation – Array Keep an array and a variable to tell where the top of the stack is. Push will put something into the array and change the top pointer Pop will return a value and change the top pointer Top will return a value and NOT change the top pointer

Stack Implementation – Linked List Use a linked list with just a few methods: Push == insert at beginning Pop == remove from beginning Top == return value of first node

Stack Uses Find parentheses pairs (or any pairs {} []…) Evaluating reverse polish (postfix) expressions Infix to postfix conversion Function call returns (allows recursion)

Queues Easy with Linked List (add to end, remove from the beginning). Need to use a circular array when implementing with an array

Header Node Have a header node at the beginning of a linked list (node created in the constructor). This way the Linked List always has a “NODE” (but it is not counted in the size). – Always skipped; has no data Now, never have to check for empty list. – Never have to change the head pointer. Most other methods have to be changed to account for the header node.