Data Structures and Database Applications Stacks in C#

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, Queues, and Linked Lists
Stacks using Linked Lists. Stack Data Structure As we already know, stacks are linear data structures. This means that their contexts are stored in what.
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.
Data Structures: A Pseudocode Approach with C
CS Data Structures II Review COSC 2006 April 14, 2017
Stacks A stack is a data structure that only allows items to be inserted and removed at one end We call this end the top of the stack The other end is.
Data Structures & Algorithms
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Summary of lectures (1 to 11)
1 Lecture 26 Abstract Data Types – IV Overview  The List ADT  Implementing Stacks as Linked List  Linked List Implementation of Queues .  Preview:
Stacks, Queues, and Deques
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.
Stacks, Queues, and Deques. 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.
Stacks, Queues, and Deques
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
CHAPTER 3 : STACKS 3.1 Understand Stacks 3.2 Implement the operation of stack By : Suzila Yusof.
Objectives of these slides:
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks.
Chapter 7 Stacks II CS Data Structures I COSC 2006
1 Joe Meehean.  Conceptual Picture access only to top item last-in-first-out (LIFO) item 1 item 2 item 3 Values in Values out 2.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
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.
Stack Implementations Chapter 6 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Circular Linked List Singly Circular Linked List Doubly Circular Linked List.
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
Chapter 7 Stacks © 2006 Pearson Addison-Wesley. All rights reserved 7A-1.
STACKS & QUEUES for CLASS XII ( C++).
Stack ADT (Abstract Data Type) N …
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Data Structure By Amee Trivedi.
Chapter 4 The easy stuff.
September 29 – Stacks and queues
Chapter 15 Lists Objectives
CS 1114: Implementing Search
Stack and Queue APURBO DATTA.
Introduction to Data Structure
Data Structures and Database Applications Queues in C#
Building Java Programs
Principles of Computing – UFCFA3-30-1
Pointers and Linked Lists
Stacks, Queues, and Deques
Database Linked List Representation
Stacks, Queues, and Deques
Stacks and Queues CSE 373 Data Structures.
CSE 214 – Computer Science II Stacks
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)))
Stacks and Queues CSE 373 Data Structures.
CSE 373 Data Structures Lecture 6
Stacks and Queues.
Program to find equivalence classes
Stacks LIFO C C B B B B A A A A A Push (A) Push (B) Push (C) Pop Pop.
Stacks and Queues CSE 373 Data Structures.
Chapter 5 Stack (part 1).
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
CS210- Lecture 6 Jun 13, 2005 Announcements
CSE 373 Data Structures Lecture 6
Stacks, Queues, and Deques
Chapter 7 © 2011 Pearson Addison-Wesley. All rights reserved.
Stack Implementations
Presentation transcript:

Data Structures and Database Applications Stacks in C#

Stack Overview System.Collections.Generic.Stack Automatic resizing and homogeneous list Represents a stack of elements

The Stack ADT A stack is a list with the restriction that insertions and deletions can only be performed at the top of the list The other end is called bottom Fundamental operations: Push: Equivalent to an insert Pop: Deletes the most recently inserted element Peek: Examines the most recently inserted element

The Stack ADT Stacks are less flexible than normal lists. But are more efficient and easy to implement Stacks are known as LIFO (Last In, First Out) lists. The last element inserted will be the first to be retrieved Stacks are analogous to a spring-loaded stack of plates in a cafeteria. Clean plates are placed on top of the stack, pushing down any already there. When a plate is removed from the stack, the one below it pops up to become the new top.

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

Creating and Traversing a Stack Example: Stack<string> numbers = new Stack<string>(); numbers.Push("one"); numbers.Push("two"); numbers.Push("three"); numbers.Push("four"); // A stack can be enumerated without disturbing its contents. Console.Write("There are {0} stack elements",numbers.Count); Console.Write(" in the following order:\n\t"); while (numbers.Peek() != null) { Console.Write(numbers.Pop()); Console.Write((numbers.Peek() != null) ? ", " : "\n")); } This prints the following two lines: There are 4 stack elements in the following order: four, three, two, one

Common C# Stack Methods Push() Pop() Peek() Clear()

Stack Database Implementation To create an efficient Database implementation of a Stack we will continue using the Tables we created in the last assignment which provided us with the Next and Prev pointers and Header fields for the size of the list, and the first and last elements of the list. We shall also continue to use those same methods we developed to get entries, and to get and set the front and rear of the list, and to clear the list, in order to develop the Stack methods that we need.

Stack Database Implementation The following implements the Push operation using the Entry Data Model and some of the get and set operations for the Linked List.

Stack Database Implementation The following implements the Pop operation using the Entry Data Model and some of the get and set operations for the Linked List.

Stack Database Implementation And the following implements the simple Peek operation.