Data Structures and Database Applications Queues 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

1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
Ceng-112 Data Structures I Chapter 5 Queues.
ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues.
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.
Queue Overview Queue ADT Basic operations of queue
CS Data Structures II Review COSC 2006 April 14, 2017
Advanced Data Structures
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Stack: Linked List Implementation Push and pop at the head of the list New nodes should be inserted at the front of the list, so that they become the top.
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.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Objectives of these slides:
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
September 05 Kraemer UGA/CSCI 2720 Lists – Part I CSCI 2720 Eileen Kraemer The University of Georgia.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Stacks And Queues Chapter 18.
Data Structures: A Pseudocode Approach with C1 Chapter 4 Objectives Upon completion you will be able to: Explain the design, use, and operation of a queue.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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.
Implementation of QUEUE For more notes and topics visit: eITnotes.com.
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.
Queues. Like Stacks, Queues are a special type of List for storing collections of entities. Stacks are Lists where insertions (pushes) and deletions (pops)
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Queue ADT for lining up politely. COSC 2006 queue2 Queue – simple collection class  first-in first-out (FIFO) structure insert new elements at one end.
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
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.
Queue ADT (Abstract Data Type) N …
COSC160: Data Structures: Lists and Queues
September 29 – Stacks and queues
Program based on queue & their operations for an application
Chapter 6 Queue.
Chapter 15 Lists Objectives
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Introduction to Data Structure
Data Structures and Database Applications Hashing and Hashtables in C#
Data Structures and Database Applications Dictionaries in C#
Building Java Programs
CMSC 341 Lecture 5 Stacks, Queues
Principles of Computing – UFCFA3-30-1
Stacks, Queues, and Deques
Database Linked List Representation
Data Structures and Database Applications Stacks in C#
Data Structures and Database Applications Hashing and Hashtables in C#
Stacks, Queues, and Deques
Lesson 6. Types Equality and Identity. Collections.
Stacks and Queues CSE 373 Data Structures.
Chapter 6 Queue.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Chapter 6 Queue.
Stacks and Queues CSE 373 Data Structures.
CSE 373 Data Structures Lecture 6
Stacks and Queues.
Stacks and Queues CSE 373 Data Structures.
CSE 373 Data Structures Lecture 6
Stacks, Queues, and Deques
CSCS-200 Data Structure and Algorithms
CMPT 225 Lecture 8 – Queue.
Presentation transcript:

Data Structures and Database Applications Queues in C#

Queue Overview System.Collections.Generic.Queue Automatic resizing and homogeneous list Represents a queue of elements

The Queue ADT A queue is another type of list collection. With a queue, insertion is done at one end (the back end), while deletion is performed at the other end (the front end). Accessing the elements of queues follows a First In, First Out (FIFO) order. Queues are analogous to customers standing in a check-out line in a store, the first customer in the line is the first customer served.

The Queue ADT Like Stacks, Queues are less flexible than normal lists. But, once again, they are more efficient and easy to implement Primary operations: Enqueue: insert an element at the rear of the list Dequeue: delete the element at the front of the list Peek: returns the first element without removing it First-in First-out (FIFO) list

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

Common C# Queue Methods Enqueue() Dequeue() Peek() Clear()

Queue Database Implementation To create an efficient Database implementation of a Queue we will continue using the Tables we used for the Stack and LinkedList operations. 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 Queue methods that we need. And, as you probably already guessed, the Dequeue() and Peek() method will have the same code as the Stack’s Pop() and Peek() methods.

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

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

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