📒
Notes
Cloud ComputingData Science/AIGame Development
  • Home
  • Big O
  • Data Structures & Algorithms
    • Data Structures
      • Array
      • Stack
      • Queue
      • Linked List
      • Binary Tree
    • Algorithms
      • Searching
      • Sorting
      • Graphs
        • Searching
        • Minimum Spanning Tree
        • Shortest Path Algorithms
      • String Algorithms
  • Object Oriented Programming
  • Languages
    • HTML/CSS
      • CSS
    • C++
    • C#
      • Types
      • Keywords
        • Modifiers
          • Access Modifiers
        • Method Parameters
      • Operators and Expressions
      • Collections
      • Constructors
      • Delegates
      • Indexers
      • Concepts
      • Features
        • LINQ
          • Operators
          • Working with Data
          • Methods
          • Resources
        • Asynchronous Programming
        • Reflection
    • Dart
    • GraphQL
    • JavaScript
      • Variable and Parameter
      • Built-in objects
        • Array
        • Built-in Functions
      • Functions
      • Classes
      • Prototype
      • Libraries
        • jQuery
        • React
          • Components
          • State and Lifecycle
          • Hooks
            • useState
            • useEffect
          • Resources
      • Testing Framework
      • Web APIs
    • Kotlin
      • Basics
    • Python
      • Basics
      • Data Structures
      • Functions
      • Resources
        • Flask
    • SQL
      • Basics
      • Operators
      • JOINs
      • Aggregations
      • Subqueries
      • Views
      • Functions
        • Window Functions
      • Stored Procedures
      • Performance Tuning
      • Extras
    • Resources
  • 🌐Web Frameworks
    • Angular
      • Templates
      • Directives
        • Attribute Directives
        • Structural Directives
    • ASP.NET
      • Fundamentals
        • Dependency Injection
        • Middleware
        • Session & State Management
      • Web apps
        • MVC
          • Controllers
            • Filters
          • Models
            • Model Binding
            • Model Validation
          • Views
            • Tag Helpers
            • View Components
          • Features
        • Client-side development
      • Web APIs
        • Controller-based APIs
        • Minimal APIs
        • OpenAPI
        • Content Negotiation
      • SignalR
      • Host and Deploy
        • IIS
      • Security
    • Django
      • The Request/Response Cycle
    • Terminologies
      • Web Server
        • Internet Information Services
    • Resources
  • 📱App Frameworks
    • Introduction
      • Resources
    • Xamarin
      • Lifecycle
      • Custom Renderers & Effects
      • Behaviors
      • Triggers
      • Gestures
      • Commands
      • Dependency Service in XF
      • Libraries
      • Showcase
    • .NET MAUI
      • Controls
      • Navigation
      • Storage Options
  • Multi-Platform Frameworks
    • .NET
      • .NET Framework
        • ADO.NET
        • WCF
      • Fundamentals
        • Logging
        • Testing
      • Advanced
        • Asynchronous Programming
        • Parallel Programming
        • Threading
        • Memory Management
          • Garbage Collection
    • Flutter
  • Object-Relational Mappers
    • Entity Framework
      • Application Models
      • Configuration
      • Setting Up
      • Advanced
  • Databases
    • Introduction
      • DBMS Architecture
      • Normalization
      • Database Transaction Models
    • Relational Databases
      • Microsoft SQL Server
        • Basics
        • Functions
        • Stored Procedures
        • Error Handling
        • Log Shipping
        • Querying and Manipulating JSON data
        • Statements
        • Topics
        • Extras
    • Non-Relational Databases
      • MongoDB
      • Redis
        • Data Structures
        • Introduction
        • Managing Database
  • Tools
    • Version Control
      • Git
        • Setup and Config
        • Basics
          • Sharing and Updating Projects
        • Resources
      • Perforce Helix
    • GitHub
    • Powershell
  • Software Development
    • Software Development Life Cycle
    • Software Design Patterns
      • GoF Design Patterns
      • Architectural Patterns
        • MVC
        • MVVM
        • N-tier Architecture
        • Onion Architecture
        • Data Transfer Objects
      • CQRS
    • Software Design Principles
      • S.O.L.I.D. Priniciple
  • System Design
    • Topics
      • Load Balancing
  • Topics
    • JWT
    • Caching
      • Static vs Dynamic Caching
    • OSI model
      • HTTP
    • Glossary
    • API
      • SOAP
      • REST
    • Microservices
    • WebHooks
    • Practice
    • Operating Systems
      • Windows
    • Architecture
  • 🔖Bookmarks
  • 🔗Resources
Powered by GitBook
On this page
  • Double-ended queue
  • Circular queue

Was this helpful?

  1. Data Structures & Algorithms
  2. Data Structures

Queue

First In First Out (FIFO)

PreviousStackNextLinked List

Last updated 2 years ago

Was this helpful?

Elements are always added to the back and removed from the front.

  • Example: A line of people waiting for a bus. The person who is at the beginning of the line is the first one to enter the bus.

  • Enqueue - If the queue is not full, this function adds an element to the back of the queue, else it prints “OverFlow”.

  • Dequeue - If the queue is not empty, this function removes the element from the front of the queue, else it prints “UnderFlow”.

Queue : Example
  • Non-Generic Queue

using System;
using System.Collections;

public class NonGenericQueueExample {
    public static void Main() {
        Console.WriteLine("Non-Generic Queue Example\n");
        var queue = new Queue();
        queue.Enqueue("Hello,");
        queue.Enqueue("World!");
	Console.WriteLine("Items in Non-Generic Queue:");
	foreach (var item in queue) {
	    Console.WriteLine(item);
	}
    }
}
  • Generic Queue

using System;
using System.Collections.Generic;

public class GenericQueueExample {
    public static void Main() {
    	Console.WriteLine("Generic Queue Example\n");
	var gQueue = new Queue<string>();
	gQueue.Enqueue("One");
	gQueue.Enqueue("Two");
	gQueue.Enqueue("Three");
	gQueue.Enqueue("Four");
	gQueue.Enqueue("Five");
	Console.WriteLine("Items in Generic Queue:");
	foreach (var item in gQueue) {
		Console.WriteLine("- " + item);
	}

	Console.WriteLine("Count: " + gQueue.Count);
	Console.WriteLine("Contains(): " + gQueue.Contains("One"));
	Console.WriteLine("Dequeue: " + gQueue.Dequeue());
	Console.WriteLine("Peek(): " + gQueue.Peek());
	Console.WriteLine("Copy of gQueue");
	var cgQueue = new Queue<string>(gQueue.ToArray());
	foreach (var item in cgQueue) {
		Console.WriteLine("- " + item);
	}

	Console.WriteLine("Copy of gQueue");
	string[] array = new string[gQueue.Count * 2];
	gQueue.CopyTo(array, gQueue.Count);
	var cgQueue2 = new Queue<string>(array);
	foreach (var cItem in cgQueue2)	{
		Console.WriteLine("- " + cItem + " ");
	}
	Console.WriteLine("Clear(): ");
	cgQueue.Clear();
	Console.WriteLine("Count: " + cgQueue.Count);
    }
}

Double-ended queue

  • In a double-ended queue, characters can be inserted and deleted from both the front and back of the queue.

Circular queue

  • A circular queue is an improvement over the standard queue structure. In a standard queue, when an element is deleted, the vacant space is not reutilized. However, in a circular queue, vacant spaces are reutilized.

  • While inserting elements, when you reach the end of an array and you need to insert another element, you must insert that element at the beginning (given that the first element has been deleted and the space is vacant).