Week 3 - Friday CS221.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Linked Lists Linear collections.
Stack & Queues COP 3502.
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, 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.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
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.
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.
1 Lecture 26 Abstract Data Types –III Overview  Creating and manipulating Linked List.  Linked List Traversal.  Linked List Traversal using Iterator.
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 CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
Stacks, Queues, and Deques
Topic 3 The Stack ADT.
Chapter 7 Stacks II CS Data Structures I COSC 2006
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Stacks and Queues Introduction to Computing Science and Programming I.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
Week 3 – Wednesday.  What did we talk about last time?  ADTs  List implementation with a dynamic array.
1 Stacks. 2 A stack has the property that the last item placed on the stack will be the first item removed Commonly referred to as last-in, first-out,
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.
Week 3 - Friday.  What did we talk about last time?  Stacks  Array implementation of a stack.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
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.
Week 5 - Wednesday.  What did we talk about last time?  Recursion  Definitions: base case, recursive case  Recursive methods in Java.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
April 27, 2017 COSC Data Structures I Review & Final Exam
Week 4 - Friday.  What did we talk about last time?  Continued doubly linked list implementation  Linked lists with iterators.
Week 4 - Wednesday.  What did we talk about last time?  Started linked lists.
0 of 36 Andries van Dam  /05/15 Reminder: TA Hour Policies If you hit a bug, you must be able to show significant effort of fixing it on your own.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
1 Example: LinkedStack LinkedStack UML Class Diagram LinkedStack Class LinkedStack Attributes/Constructor LinkedStack Methods LinkedStack iterator method.
Click to edit Master text styles Stacks Data Structure.
Data Structures Intro2CS – week Stack ADT (Abstract Data Type) A container with 3 basic actions: – push(item) – pop() – is_empty() Semantics: –
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.
Section 3.7 Linked-Based Implementations
Linked Data Structures
Stack: a Linked Implementation
Week 4 - Monday CS221.
Week 4 - Friday CS221.
Lecture No.06 Data Structures Dr. Sohail Aslam
Data Structures and Algorithms
Stacks.
Week 6 - Wednesday CS221.
Stacks and Queues.
The Stack ADT. 3-2 Objectives Define a stack collection Use a stack to solve a problem Examine an array implementation of a stack.
Stacks.
Week 15 – Monday CS221.
Stack and Queue APURBO DATTA.
Stacks Stack: restricted variant of list
COMPUTER 2430 Object Oriented Programming and Data Structures I
CMSC 341 Lecture 5 Stacks, Queues
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Circular List removedNode General Case Single Node Case lastNode aNode
Lesson Objectives Aims
Data Structures and Algorithms
COMPUTER 2430 Object Oriented Programming and Data Structures I
More Data Structures (Part 1)
Stacks CS-240 Dick Steflik.
Lists.
Stacks, Queues, and Deques
CS210- Lecture 3 Jun 6, 2005 Announcements
Week 6 - Monday CS221.
CMPT 225 Lecture 7 – Stack.
Data Structures & Programming
CHAPTER 3: Collections—Stacks
Presentation transcript:

Week 3 - Friday CS221

Last time What did we talk about last time? Array implementation of a list

Questions?

Assignment 2

Project 1 Bitmap Manipulator

Assignment 1 issues Most people messed up the add() method that takes an index Most people didn't throw exceptions at quite the right times or didn’t throw them at all There was a lot of inconsistent formatting I don't specify what your formatting should be too closely, but it should be consistent Check out the coding standards for the course: http://users.etown.edu/w/wittmanb/cs221/standards/

Specific Assignment 1 don'ts Don't create a new Node unless you have to: Never look at the next thing unless you have to: Node temp = new Node(); //wastes memory temp = head; public boolean contains(int element) { Node temp = head; while(temp.next != null){ //two different bugs if( temp.value.equals(element) ) return true; temp = temp.next; } return false;

Specific Assignment 1 don'ts Don't use == to compare two String objects! public boolean contains(int element) { Node temp = head; while(temp != null){ // following might not work! if( temp.value == element) ) return true; temp = temp.next; } return false;

String comparison What happens when you use == for String comparison? String a = "Goats"; String b = "Goats"; String c = new String("Boats"); String d = new String("Boats"); if( a == b ) // prints System.out.println("a == b"); if( c == d ) // doesn't print System.out.println("c == d");

Specific Assignment 1 do's Use other methods to simplify code: Except when it doesn't make sense Using get() in addAll() is inefficient Keep it simple: Test, test, test! public boolean contains(int element) { return indexOf(element) != -1; } public boolean isEmpty() { return size == 0; }

Stacks Impromptu Student Lecture

Stacks

Stack A stack is a simple (but useful) ADT that has three basic operations: Push Put an item on the top of the stack Pop Remove an item from the top of the stack Top Return the item currently on the top of the stack (sometimes called peek)

Keeping track of things When are stacks used? Implicitly, in recursion (or in any function calls) Explicitly, when turning recursive solutions into iterative solutions When parsing programming languages When converting infix to postfix

Implementations

Array implementations Advantages: Pop is Θ(1) Top is Θ(1) Disadvantages Push is Θ(n) in the very worst case, but not in the amortized case

Array implementation public class ArrayStack { private int[] data; private int size; public ArrayStack() {} public void push(int value) {} public int pop() {} public int peek() {} //instead of top public int size() {} }

Array Constructor

Array Push

Array Pop

Array Peek

Array Size

Upcoming

Next time… Queue implementation with dynamic array Linked lists

Reminders Keep reading section 1.3 Finish Assignment 2 Due tonight by 11:59pm Keep working on Project 1 Due next Friday, September 22 by 11:59pm