CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Advertisements

Stack & Queues COP 3502.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
0 of 37 Stacks and Queues Lecture of 37 Abstract Data Types To use a method, need to know its essentials: signature and return type o additionally,
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
CS 206 Introduction to Computer Science II 03 / 23 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 12 / 04 / 2006 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 06 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 17 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 04 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 20 / 2009 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 15 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 29 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 16 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
CS 206 Introduction to Computer Science II 10 / 08 / 2008 Instructor: Michael Eckmann.
1 Lecture 26 Abstract Data Types – IV Overview  The List ADT  Implementing Stacks as Linked List  Linked List Implementation of Queues .  Preview:
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 28 / 2009 Instructor: Michael Eckmann.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Stacks and Queues Introduction to Computing Science and Programming I.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition 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,
September 05 Kraemer UGA/CSCI 2720 Lists – Part I CSCI 2720 Eileen Kraemer The University of Georgia.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
CS 106 Introduction to Computer Science I 04 / 25 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 13 / 2009 Instructor: Michael Eckmann.
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Arrays and Collections Tonga Institute of Higher Education.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
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.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Computer Engineering Rabie A. Ramadan Lecture 6.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15 1.
Click to edit Master text styles Stacks Data Structure.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Chapter 12 – Data Structures
Chapter 15 Lists Objectives
Stacks and Queues.
Stack and Queue APURBO DATTA.
Principles of Computing – UFCFA3-30-1
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Abstract Data Type Abstract Data Type as a design tool
Stacks and Queues.
Lecture 16 Stacks and Queues CSE /26/2018.
Presentation transcript:

CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Fall 2006 Today’s Topics Comments and/or Questions? Prog 2 grading –I sent an with some commentary on some ways you could get points off –I still need to do the EC for some of you --- if you have nothing written in the Extra Credit: ________ it means I haven't checked it out yet. –If you have a 0 there it means I don't believe I got EC from you. Queues Stacks

Linked lists Compare a linked list's behaviors to that of arrays and ArrayLists. – Which are dynamic in length? – How about ease of operations in terms of: speed of execution and programmer ease – Consider these operations: Add Insert Delete

Queues and Stacks A queue is a data structure that has the following characteristics – It is linear – Uses FIFO (first in, first out) processing Queue operations – Enqueue – add an item to the rear of the queue – Dequeue – remove an item from the front of the queue – Empty – returns true if the queue is empty What's significant about a queue is that there are no insert in anywhere or remove from anywhere in the queue. The only place to add something to the queue is the rear, and the only place to remove something from the queue is the front.

Queues and Stacks A stack is a data structure that has the following characteristics – It is linear – Uses LIFO (last in, first out) processing Stack operations – Push – add an item to the top of the stack – Pop – remove an item from the top of the stack – Empty – returns true if the stack is empty – Peek – retrieve information about the item on top of the stack without removing it The only allowable ways to put an item into and to get an item from the stack is via push and pop. There are no insert in anywhere or remove from anywhere in the stack. What if there was no peek? Is it redundant --- could a series of the existing operations achieve the same functionality.

Queues and Stacks Can anyone think of real world examples that are naturally modeled by queues? Can anyone think of a real world example that is naturally modeled by a stack? Let's see visual representations of a queue and a stack on the board.

Queues and Stacks Can anyone think of real world examples that are naturally modeled by queues? – Line of people at grocery store checkout – Line of airplanes waiting for takeoff Can anyone think of a real world example that is naturally modeled by a stack? – Plates at a salad bar A customer takes the top plate (pop) When new plates come out, they are “pushed” to the top of the stack. – Why is this example not a queue?

Queues and Stacks Recursive method calls A new call to the method causes it's local data to be popped onto the stack The method calls finish in reverse order, so when a method call ends, it's local data is popped off the stack

Queues and Stacks Could we implement a Queue with – a linked list – an array Could we implement a Stack with – a linked list – an array

Implementing a Stack Properties of a Stack –linear data structure –LIFO processing What operations should be available to Stacks? –push –pop –peek –empty?

Implementing a Stack If we were implementing the data on the Stack as an array of elements of some type, we would give a maximum length to our array. What else would we need to store to allow push, pop, peek and empty? to work?

Implementing a Stack If we were implementing the data on the Stack as an array of elements of some type, we would give a maximum length to our array. What else would we need to store to allow push, pop, peek and empty? to work? –top_of_stack we have two choices of what this will hold –either the index of the next place to push –or the index of the place to pop So, for an empty stack what value would top_of_stack have ?

Implementing a Stack Let's say we're representing a stack of Strings. public class Stack { private String the_stack[]; private int top_of_stack; public Stack(int max_size) { the_stack = new String[max_size]; } // anything else need to go in the constructor?

Implementing a Stack Let's say we're representing a stack of Strings. public class Stack { private String the_stack[]; private int top_of_stack; public Stack(int max_size) { the_stack = new String[max_size]; top_of_stack = -1; } // we can continue this in eclipse now.

Implementing a Queue What ideas do you have?