Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures and Database Applications Queues in C#

Similar presentations


Presentation on theme: "Data Structures and Database Applications Queues in C#"— Presentation transcript:

1 Data Structures and Database Applications Queues in C#

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

3 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.

4 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

5 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

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

7 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.

8 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.

9 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.

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


Download ppt "Data Structures and Database Applications Queues in C#"

Similar presentations


Ads by Google