מחסנית ותור Stacks and Queues. מחסנית Stack מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out)

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Stacks and Queues. Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about.
Data Structure HKOI training /4/2010 So Pak Yeung.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
CS Data Structures II Review COSC 2006 April 14, 2017
Data Structures & Algorithms
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
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.
Stacks.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Queues.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
שימוש במערך דינמי : ArrayList. מאפיינים חשובים בכל LIST יכולת להכניס מידע בלי תלות בטיפוס יכולת למחוק מידע יכולת להוסיף מידע פונקציות נוספות ( מיון, חיפוש.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
מחסנית (Stack): מבנה נתונים עליו מוגדרות הפעולות הבאות:
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Data Structures from Cormen, Leiserson, Rivest & Stein.
Stacks and Queues. Stack ADT סוג של מערך מוגבל מהר מאוד ולוקחים מעט זכרון שימוש ב LIFO – LIFO (Last In, First Out) lists. –אפשר להוסיף רק בסוף הרשימה.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 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.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Structure. מה לומדים היום ? דרך לבנות מבנה נתונים בסיסי – Structure מייצר " טיפוס " חדש מתאים כאשר רוצים לאגד כמה משתנים יחד דוגמאות : עובד : שם, טלפון,
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
Stacks and Queues Introduction to Computing Science and Programming I.
Dr. Salah Hammami KSU-CCIS-CS Ahmad Al-Rjoub CSC 113 King Saud University College of Computer and Information Sciences Department of Computer Science Chapter.
1/ 124 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 18 Programming Fundamentals using Java 1.
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
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.
CMSC 202 Stacks and Queues. What’s a Queue? A queue is a linear collection of homogeneous data in which items added to the queue must be placed at the.
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’
Foundation of Computing Systems Lecture 3 Stacks and Queues.
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.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
Foundations of Data Structures Practical Session #4 Recurrence ADT 08/04/2013Amihai Savir & Ilya Mirsky
מחסנית ותור Stacks and Queues. מחסנית Stack מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out)
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.
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.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
Queues 1. Queue  a queue represents a sequence of elements where elements can be added at the back of the sequence and removed from the front of the.
CS-2851 Dr. Mark L. Hornick 1 Stacks and Queues Behavior vs. Structure.
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: –
Lecture 16 Stacks and Queues Richard Gesick. Sample test questions 1.Write a definition for a Node class that holds a number. 2.Write a method that sums.
G64ADS Advanced Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
QueueStack CS1020.
September 29 – Stacks and queues
Chapter 15 Lists Objectives
Chapter 12: Data Structures
Stacks and Queues.
מחלקות classes.
Data Structures and Database Applications Queues in C#
Building Java Programs
Principles of Computing – UFCFA3-30-1
Web Services אוספים - Collections ליווי מקצועי : ארז קלר
Lecture 21 Stacks and Queues Richard Gesick.
מחסנית ותור Stacks and Queues.
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.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Lecture 16 Stacks and Queues CSE /26/2018.
Abstract Data Type (ADT)
Lecture 16 Stacks and Queues CSE /26/2018.
CMPT 225 Lecture 8 – Queue.
Data Structures & Programming
Presentation transcript:

מחסנית ותור Stacks and Queues

מחסנית Stack

מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out) lists. –אפשר להוסיף רק בסוף הרשימה PUSH –אפשר להוריד רק מסוף הרשימה POP (ADT – Abstract Data Type)

הפעולות הבסיסיות : השימוש של STACK הוא LIST עם מגבלות –אפשר להוסיף רק לראש הרשימה – PUSH סוג של INSERT – POP סוג של REMOVE – PEEK דרך לראות את הערך בראש הרשימה – הדרך היחידה לראות ערכים בלי להוריד אותם !

Push and Pop Primary operations: Push and Pop Push – Add an element to the top of the stack Pop – Remove the element at the top of the stack A top empty stack top push an elementpush another A B pop A

דוגמא של POP Module Module1 Sub Main() Dim test As New Stack() Dim i As Integer For i = 1 To 5 test.Push(i) Next Console.WriteLine(test.Count) For i = 1 To test.Count Dim num As Integer = test.Pop() Console.WriteLine(num) Next End Sub End Module

דוגמא של PEEK Module Module1 Sub Main() Dim test As New Stack() Dim i As Integer For i = 1 To 5 test.Push(i) Next Console.WriteLine(test.Count) For i = 1 To test.Count Dim num As Integer = test.Peek() Console.WriteLine(num) Next End Sub End Module

להמציא מחדש את הגלגל ( עם פונקציות ) Module Module1 Function Count(ByVal list As ArrayList) As Integer Return list.Count() End Function Sub Push(ByVal val As Object, ByRef list As ArrayList) list.Add(val) End Sub Function Pop(ByVal list As ArrayList) As Object Dim obj As Object = list.Item(list.Count - 1) list.RemoveAt(list.Count - 1) Return obj End Function Function Peek(ByVal list As ArrayList) As Object Return list.Item(list.Count - 1) End Function המשך....

להמציא מחדש את הגלגל, המשך Sub Main() Dim test As New ArrayList() Dim i As Integer For i = 0 To 4 Push(i, test) Next Console.WriteLine(Count(test)) For i = 0 To test.Count - 1 Dim num As Integer = Pop(test) Console.WriteLine(num) Next End Sub End Module

תור Queue

Queue ADT סוג אחר של מערך מוגבל מהיר מאוד, ולוקח מעט זיכרון שימוש ב FIFO – FIFO (First In, First Out) lists. –אפשר להוסיף רק בסוף הרשימה Enqueue –אפשר להוריד רק מהתחלת הרשימה Dequeue

דוגמא Module Module1 Sub Main() Dim queue As New Queue Dim i As Integer For i = 1 To 5 queue.Enqueue(i) Next For i = 1 To queue.Count Console.WriteLine(queue.Dequeue()) Next End Sub End Module

תרגיל : איך בונים QUEUE ( עם פונקציות )? Function Count(ByVal list As ArrayList) As Integer Return list.Count() End Function Sub Enqueue(ByVal val As Object, ByRef list As ArrayList) ??? End Sub Function Dequeue(ByVal list As ArrayList) As Object ??? End Function Function Peek(ByVal list As ArrayList) As Object Return list.Item(0) End Function

תרגיל : לחשב מחיר על בסיס LIFO וגם FIFO QUEUE ל FIFO STACK ל LIFO יש לבנות מבנה עם מחיר וכמות יש להכניס ערכים לתוך STACK ו QUEUE – Push, Enqueue יש לחשב את המחיר לפי הפונקציות : – DEQUEUE ( ל QUEUE) – POP ( ל STACK)

איך מתחילים ?? Structure Stock Dim Amount As Integer Dim Price As Decimal End Structure Module Module1 Sub Main() Dim List1 As New Queue() Dim List2 As New Stack() Dim temp As Stock temp.Amount = 10 temp.Price = 5.5 List1.Enqueue(temp) List2.Push(temp) temp.Amount = 50 temp.Price = 8.5 List1.Enqueue(temp) List2.Push(temp) temp = List1.Peek() Console.WriteLine("What's the cost? " & temp.Price) temp = List2.Peek() Console.WriteLine("What's the cost? " & temp.Price) End Sub End Module