FAtechs is a Web Site where you can find a lot of things related to tech and Education. Our Posts are mostly about Programming, Information, Technology,Software, Reviews & Everything You need to Know. You can also find Books and Novels here. Your appreciation and criticism will be welcomed.
Queue Collection in Data Structures Using Built-in Functions of C#
Queues in Data Structures:
Queue is a collection same as list but it is a FIFO (First In First Out) Collection. It means the element that is entered in a queue at first will the come out at first position. In more easy words whenever we Enqueue (insert) an element in the Queue First will Dequeue (remove) first whenever we want to delete and element of the Queue. It will work like this because Enqueue will insert elements is rear of a queue and after new element is inserted the rear element will go down and new element takes the rear place and Dequeue deletes the element at the Front of the queue which is the oldest one.
Basic Queue Operations:
New() : Creates a new Queue.
Enqueue() : Inserts Object or element in the Rear of the Queue.
Dequeue() : Deletes Object or element from the Front of the Queue.
Front() : Returns the Object or element in the Front of the Queue but does not delete it from the Stack.
Size() : Returns the number of Object or element in the Queue i.e. Size of the Queue
IsEmpty() : It is a Boolean Function, It Indicates that the Queue is empty or not.
Code of Queue Collection in C#:
Queue<int> numbers = newQueue<int>(); // initialization,
int is the data type and numbers is the name of queue
numbers.Enqueue(100); //100 will be entered in the rear of queue
numbers.Enqueue(200); // 200 will bw entered and now 200 is on rear
numbers.Enqueue(300); // now 300 is on rear of the queue
numbers.Dequeue(); // front (First inserted) value 100 will be deleted and
200 will become the first(Front) value
numbers.Dequeue(); // 200 will be deleted and 300 will become the Front value
Return the Front object
foreach (int a in numbers) // displaying all
Queue members using foreach loop
staticvoid Main(string args)
Code c = newCode();
Hit Like Button if you understood, It helps a lot to keep us Motivated.