FIFO ( First | C # program to demonstrate working of FIFO ; Driver code ; Adds elements { 0 , 1 , 2 , 3 , 4 } to queue ; Display contents of the queue . ; To remove the head of queue . In this the oldest element '0' will be removed ; To view the head of queue ; Rest all methods of collection interface , Like size and contains can be used with this implementation .
using System ; using System . Collections . Generic ; public class QueueExample { public static void Main ( String [ ] args ) { Queue < int > q = new Queue < int > ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) q . Enqueue ( i ) ; Console . Write ( " Elements ▁ of ▁ queue - " ) ; foreach ( int s in q ) Console . Write ( s + " ▁ " ) ; int removedele = q . Dequeue ( ) ; Console . Write ( " STRNEWLINE removed ▁ element - " + removedele + " STRNEWLINE " ) ; foreach ( int s in q ) Console . Write ( s + " ▁ " ) ; int head = q . Peek ( ) ; Console . Write ( " STRNEWLINE head ▁ of ▁ queue - " + head ) ; int size = q . Count ; Console . WriteLine ( " STRNEWLINE Size ▁ of ▁ queue - " + size ) ; } }