0% found this document useful (0 votes)
9 views1 page

Queue C

The document demonstrates how to use a queue data structure in C# by creating a queue of strings, adding elements, removing the first element, peeking at the first element, checking if an element is contained, and clearing the queue.

Uploaded by

Tommy Marcelino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Queue C

The document demonstrates how to use a queue data structure in C# by creating a queue of strings, adding elements, removing the first element, peeking at the first element, checking if an element is contained, and clearing the queue.

Uploaded by

Tommy Marcelino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.Collections.Generic;

namespace DSA_QUEUE
{
class Program
{
static void Main(string[] args)
{
//CREATE A QUEUE
Queue<string> studq = new Queue<string>();

//INSERT A ELEMENT IN THE QUEUE


studq.Enqueue("John");
studq.Enqueue("Janwell");
studq.Enqueue("Syrajean");
studq.Enqueue("Aljon");
studq.Enqueue("Angel");

foreach (var s in studq)


Console.WriteLine(s);

//REMOVES FIRST ONE IN QUEUE


studq.Dequeue();

Console.WriteLine("");
foreach (var s in studq)
Console.WriteLine(s);

Console.WriteLine("");
//PEEK

Console.WriteLine(studq.Peek());

Console.WriteLine("");
//CONTAINS
Console.WriteLine(studq.Contains("Angelica"));

//CLEAR
studq.Clear();

if (studq.Count == 0)
{
Console.WriteLine("No one in queue!");
}

}
}
}

You might also like