We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byJoleen Clark
Modified over 4 years ago
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007
© 2004 Pearson Addison-Wesley. All rights reserved12-2 Outline Collections and Data Structures Dynamic Representations Queues and Stacks Trees and Graphs The Java Collections API
© 2004 Pearson Addison-Wesley. All rights reserved12-3 Classic Data Structures Now we'll examine some classic data structures Classic linear data structures include queues and stacks
© 2004 Pearson Addison-Wesley. All rights reserved12-4 Queues A queue is similar to a list but adds items only to the rear of the list and removes them only from the front It is called a FIFO data structure: First-In, First-Out Analogy: a line of people at a bank teller’s window enqueue dequeue
© 2004 Pearson Addison-Wesley. All rights reserved12-5 Queues We can define the operations for a queue enqueue - add an item to the rear of the queue dequeue (or serve) - remove an item from the front of the queue empty - returns true if the queue is empty As with our linked list example, by storing generic Object references, any object can be stored in the queue Queues often are helpful in simulations or any situation in which items get “backed up” while awaiting processing
© 2004 Pearson Addison-Wesley. All rights reserved12-6 Queues A queue can be represented by a singly-linked list; it is most efficient if the references point from the front toward the rear of the queue A queue can be represented by an array, using the remainder operator (%) to “wrap around” when the end of the array is reached and space is available at the front of the array
© 2004 Pearson Addison-Wesley. All rights reserved12-7 Stacks A stack ADT is also linear, like a list or a queue Items are added and removed from only one end of a stack It is therefore LIFO: Last-In, First-Out Analogies: a stack of plates in a cupboard, a stack of bills to be paid, or a stack of hay bales in a barn
© 2004 Pearson Addison-Wesley. All rights reserved12-8 Stacks Stacks often are drawn vertically: poppush
© 2004 Pearson Addison-Wesley. All rights reserved12-9 Stacks Some stack operations: push - add an item to the top of the stack pop - remove an item from the top of the stack peek (or top) - retrieves the top item without removing it empty - returns true if the stack is empty A stack can be represented by a singly-linked list; it doesn’t matter whether the references point from the top toward the bottom or vice versa A stack can be represented by an array, but the new item should be placed in the next available place in the array rather than at the end
© 2004 Pearson Addison-Wesley. All rights reserved12-10 Stacks The java.util package contains a Stack class Like ArrayList operations, the Stack operations operate on Object references
© 2004 Pearson Addison-Wesley. All rights reserved12-11 Summary Chapter 12 has focused on: the concept of a collection separating the interface from the implementation dynamic data structures linked lists queues and stacks trees and graphs generics
Data Structures Part 2 Stacks, Queues, Trees, and Graphs Briana B. Morrison CSE 1302C Spring 2010.
Chapter 9: Data Structures I
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
CS Data Structures II Review COSC 2006 April 14, 2017
Data and information These are philosophical categories These are philosophical categories We are not able to give exact definition We are not able to.
CISH 4960 Introduction to Programming Lecture 101 Introduction to Programming Lecture 10 Recursion/Data Structures Tom Blough
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Chapter 12: Data Structures
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
1 Data Structures We can now explore some advanced techniques for organizing and managing information Chapter 12 of the book focuses on: dynamic structures.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
TCSS 342, Winter 2005 Lecture Notes
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
© 2020 SlidePlayer.com Inc. All rights reserved.