Problem of the Day  At what times do the minute and hour hands on an analog clock line up?

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

1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 116.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 107.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 40.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 28.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 44.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 38.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 58.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 75.
1 Introduction to Computation and Problem Solving Class 23: Introduction to Data Structures: Stacks and Queues Prof. Steven R. Lerman and Dr. V. Judson.
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Stacks.
What Time Is It? Lesson by Mrs. Moody, FLE. M1M2 Students will develop an understanding of the measurement of time. a Tell time to the nearest hour and.
Break Time Remaining 10:00.
Linked List A linked list consists of a number of links, each of which has a reference to the next link. Adding and removing elements in the middle of.
Chapter 24 Lists, Stacks, and Queues
COSC 1P03 Data Structures and Abstraction 10.1 The List If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping.
CSE Lecture 12 – Linked Lists …
We are learning how to read the 24 hour clock
Lecture Stacks. A stack is a Last-In-First-Out (LIFO) or a First-In-Last-Out (FILO) abstract data type E.g. a deck of cards in which cards may be added.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 11: Priority Queues and Heaps Java Software Structures: Designing.
: 3 00.
5 minutes.
Clock will move after 1 minute
Select a time to count down from the clock above
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
Elementary Data Structures CS 110: Data Structures and Algorithms First Semester,
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Introduction to Stacks What is a Stack Stack implementation using arrays. Application of Stack.
Stacks.
Introduction to Stacks What is a Stack Stack implementation using array. Stack implementation using linked list. Applications of Stack.
Stacks. 2 Outline and Reading The Stack ADT (§2.1.1) Array-based implementation (§2.1.1) Growable array-based stack (§1.5) Java.util.Stack class Java.util.Vector.
Part-B1 Stacks. Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations.
CHAPTER 6 Stacks Array Implementation. 2 Stacks A stack is a linear collection whose elements are added and removed from one end The last element to be.
Stacks. 2 Outline and Reading The Stack ADT (§2.1.1) Applications of Stacks (§2.1.1) Array-based implementation (§2.1.1) Growable array-based stack (§1.5)
Abstract Data Type (ADT) & Stacks
Chapter 3 Introduction to Collections – Stacks Modified
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Chapter 7 Stacks. © 2004 Pearson Addison-Wesley. All rights reserved 7-2 The Abstract Data Type: Developing an ADT During the Design of a Solution Specifications.
CSC 212 Stacks & Queues. Announcement Many programs not compiled before submission  Several could not be compiled  Several others not tested with javadoc.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
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.
LECTURE 24: STACK ADTS CSC 212 – Data Structures.
CSC 212 – Data Structures Lecture 17: Stacks. Question of the Day Move one matchstick to produce a square.
Question of the Day  Three people check into a hotel for which they pay the manager $30. The manager finds out the rate is $25 and gives $5 to the bellboy.
LECTURE 27: DEQUES CSC 212 – Data Structures. Roses are red and violets are blue Implement push, pop, & top And you’re a Stack too! Stack & ADT Memory.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Stack. ADS2 Lecture 1010 The Stack ADT (GoTa §5.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in.
Stacks. What is a Stack? A stack is a type of data structure (a way of organizing and sorting data so that it can be used efficiently). To be specific,
Click to edit Master text styles Stacks Data Structure.
1 Stacks Abstract Data Types (ADTs) Stacks Application to the analysis of a time series Java implementation of a stack Interfaces and exceptions.
Generics, Exception and Undo Command. A Generic Stack Class AStack uses generic. In the main method, we have 2 instances of AStack, each type is Integer.
Sections 3.4 Formal Specification
Elementary Data Structures
Generics, Exceptions and Undo Command
Stacks.
CSE 116/504 – Intro. To Computer Science for Majors II
Stacks.
Lecture 5 Stacks King Fahd University of Petroleum & Minerals
Stacks Abstract Data Types (ADTs) Stacks
Presentation transcript:

Problem of the Day  At what times do the minute and hour hands on an analog clock line up?

Problem of the Day  At what times do the minute and hour hands on an analog clock line up? Hands overlap one anotherHands opposite one another 12:00: :05: :10: :16: :21: :27: :32: :38: :43: :49: :54: :00: :05: :10: :16: :21: :27: :32: :38: :43: :49: :54:32.727

CSC 212 – Data Structures

Rest of the Year

ADTs Mean Interface s  Each ADT is defined by single Interface  Guarantees methods exist & what they should do  But classes are free to implement however they want  Programmer knows from the interface :  Each of the method signatures  Value returned by the method  The effects of the method’s actions  Why Exception s thrown by method

View of an ADT IOU

You Other Coder IOU

View of an ADT You Other Coder IOU ADT

 ADTs must remain abstract  Any implementation okay, if it completes methods  Could implement an ADT with: Implementing ADT

 ADTs must remain abstract  Any implementation okay, if it completes methods  Could implement an ADT with:  Array Implementing ADT

 ADTs must remain abstract  Any implementation okay, if it completes methods  Could implement an ADT with:  Array  Linked list Implementing ADT

 ADTs must remain abstract  Any implementation okay, if it completes methods  Could implement an ADT with:  Array  Linked list  Trained monkeys Implementing ADT

 ADTs must remain abstract  Any implementation okay, if it completes methods  Could implement an ADT with:  Array  Linked list  Trained monkeys  College students Implementing ADT

Is linked list an ADT?

 Linked lists have very specific implementation  Singly-, & doubly-linked versions exist…  … but implementation impossible using an array  No trained monkeys could do same work  Linked lists also do not specify functionality  No standard way to access or use data  In fact, there is no interface serving as guarantee! Why is linked list not ADT?

Implementation vs. ADT ImplementationADT

 Superinterface for all our ADTs  Define methods common to all data structures  Access & usages patterns differ with each ADT Collection Classes

 Superinterface for all our ADTs  Define methods common to all data structures  Access & usages patterns differ with each ADT public interface Collection { public int size(); public boolean isEmpty(); } Collection Classes

 Superinterface for all our ADTs  Define methods common to all data structures  Access & usages patterns differ with each ADT public interface Collection { public int size(); public boolean isEmpty(); } Collection Classes

 Superinterface for all our ADTs  Define methods common to all data structures  Access & usages patterns differ with each ADT public interface Collection { public int size(); public boolean isEmpty(); } Collection Classes

 Awwww… our first collection class  Works like PEZ dispenser:  Add by pushing data onto top  Pop top item off to remove impossible  Accessing other values impossible  Top item only is available  Cheap plastic/private fields get in way Stacks

Applications of Stacks  Stacks are used everywhere  Back & Forward buttons in web browser  Powerpoint’s Undo & Redo commands  Methods’ stackframes used during execution  Java uses stacks to execute operations in program

 Defines two vital methods…  push(obj)  add obj onto top of stack  pop()  remove & return item on top of stack  … an accessor method…  top()  return top item (but do not remove it)  … and Collection ’s methods…  size()  returns number of items in stack  isEmpty()  states if stack contains items Stack ADT

 ADT also defines own exception public class EmptyStackException extends RuntimeException { public EmptyStackException(String err) { super(err); } }  EmptyStackException is unchecked  Need not be listed in throws, but could be  Unchecked since there is little you can do to fix it  try-catch not required, but can crash program More Stack ADT

public interface Stack extends Collection { public E top() throws EmptyStackException; public E pop() throws EmptyStackException; public void push(E element); }  Any type of data stored within a Stack  Generics enable us to avoid rewriting this code  Minimum set of exceptions defined by interface  Classes could throw more unchecked exceptions Stack Interface

Using Stack

Your Turn  Get into your groups and complete activity

For Next Lecture  Read GT5.1.2 – for Friday’s class  How can we use an array to implement a Stack?  Linked-list based approaches possible, too?  Why would we prefer one over the other?  Week #8 weekly assignment due on Tuesday  Programming assignment #1 also on Angel  Pulls everything together and shows off your stuff  Better get moving on it, since due in 10 days!