Stack and Queue

Stack and Queue


Stack is a linear data structure that follows a particular order in which the operators performed. The order can be "Last to enter First to get out" or "First to enter First to Get Out". In C# stack has 4 basic operators which are Push, Pop, Peek, isEmpty. Push is used to add an item in the stack. Pop is used to remove an item in the stack. Peek is used to return the object at the beginning of the stack without removing it. Clear is used to remove all objects in the stack. But before all this we need to use the command Stack() to create the stack Stack stack_name = new Stack();.

A Queue is a linear structure which follows a particular order in which the operations are performed. The ordering used in queue is First in First out. 

To create a Queue we have 4 constructors which are used in making them. Queue(), Queue(collection), Queue(Int32), Queue(Int32, Single).(Queue queue_name = new Queue();)
To add a queue we use Enqueue() to add something to the queue. To remove we use Dequeue to remove a certain object and we use Clear to remove everything. To get the beginning of the queue we use Peek.

Comments

Popular posts from this blog