The process of collecting and organizing data in the best way is known as Data Structures. Here the operations on data are performed in an efficient way. Its functionality supports a specific purpose of accessing and performing operations in a given appropriate ways.
There are two types for structuring and managing the data.
Stacks: It is used to add or remove objects or files in memory in a particular order. The order is generally known as LIFO, i.e., Last In First Out. In this stack there are only two operations which are push and pop. Push is used to insert the objects into the stack where as pop is used to bring the item out of the stack. As there is only one end to the stack, the objects can be removed or inserted only from the top end. Whenever we add an element into the stack, it goes on the top of the existing element. Here we can only remove the element that is on the top of the stack. You can think of the stack as the pile of objects or files. Here we can’t remove the first inserted object without removing out the rest of the objects on its top. A stack is called as a recursive data structure.
Queue: This is a linear collection or a container of objects. Queue follows an order of inserting and removing of elements known as FIFO, i.e., First In First Out. It is also known as a linear data structure. Here there are 2 ends for a queue. First element is inserted into the queue from one end called REAR which is also called the tail, and the deletion or removal of the existing element can be done through the other end which is also known as the head.
Here its functionality is that the element that is entered first is the element that has to be removed first. Enqueue is the process of adding an object into the queue which is done at the back of the queue, whereas Dequeue is the process of removing an existing object from the queue through the front end. You can think of a group of people standing in a queue for tickets as an example of Queue data structure.
Though the purpose is same the process is different in the stack and queue. Difference is in the way the objects are removed from the pile of objects. The most recently added object is removed from the stack, where as the last recently added item is removed from the queue.
Uses of these structures are:
1. In software design, stack and queue are known to be major factors for collection, storing and organising of data rather than algorithms in some programming languages.
2. In almost every software system and program, these are often included now-a-days.
3. Often these are used in the combination of algorithms. This allows the management of large amounts of data in an efficient way.