Enqueue and dequeue : Queue : Data Structure C# Examples


C# Examples » Data Structure » Queue »

 

Enqueue and dequeue









    
using  System;  
using  System.Collections;  
    
class  MainClass  {  
  
    public  static  void  Main()  {  
        Queue  q  =  new  Queue();  
  
        q.Enqueue(1);  
        q.Enqueue(2);  
        q.Enqueue(3);  
        q.Enqueue(4);  
  
        Console.Write("queue:  ");  
        foreach(int  i  in  q)  
            Console.Write(i  +  "  ");  
  
        Console.WriteLine();                  

        Console.Write("Dequeue  ->  ");  
        int  a  =  (int)  q.Dequeue();  
        Console.WriteLine(a);  
  
        Console.Write("queue:  ");  
        foreach(int  i  in  q)  
            Console.Write(i  +  "  ");  
  
        Console.WriteLine();                  
  
    }  
}
    
   
  
   



Output

queue: 1 2 3 4
Dequeue -> 1
queue: 2 3 4


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Queue