What is the difference between stack and linked list?Ī stack is an abstract data type that serves as a collection of elements with two principal operations which are push and pop. Queue is used in solving problems having sequential processing. Stack is used in solving problems works on recursion. The front pointer always points to the first element inserted in the list and is still present, and the rear pointer always points to the last inserted element. In queues we maintain two pointers to access the list. ![]() ![]() In stacks we maintain only one pointer to access the list, called the top, which always points to the last element present in the list. Insert operation is called enqueue operation.ĭelete operation is called pop operation.ĭelete operation is called dequeue operation. Insert operation is called push operation. The insertion takes place at the rear of the list and the deletion takes place from the front of the list. Insertion and deletion in queues takes place from the opposite ends of the list. Insertion and deletion in stacks takes place only from one end of the list called the top. ![]() ![]() Queues are based on the FIFO principle, i.e., the element inserted at the first, is the first element to come out of the list. Stacks are based on the LIFO principle, i.e., the element inserted at the last, is the first element to come out of the list. Difference between Stack and Queue Data Structures Stacks
0 Comments
Leave a Reply. |