Coders Packet

Implementation of Stack and Queue using Linked lists in C++

By Gudipati Ganesh Yaswanth Kumar

This packet of code deals with data structures especially Stack and Queue, along with their basic operations.

Data Structures can be defined as the way of organizing data so that it can be effectively used by the system. We have plenty of data structures like an array, stack, queue, linked list, heap, tree, graph, etc. Stack and queue are the most basic and important among these. These two can be implemented either with the assistance of arrays or linked lists.

Stack vs Queue

Stack: Stack works on the LIFO principle (Last in First out). The most recently added item is removed first.

Queue: Queue works on the FIFO principle(First in First out). The least recently added item is removed first.

Arrays vs Linked List

1. Arrays require contiguous memory allocation.

2. Size of the array should be given in prior.

3. Once an array is created we cannot vary the size of the array.

4. While in Linked lists, memory locations of elements need not be contiguous.

5. We can have a pointer attached with each element that drives us from the current location to the location the of next element.

6. We can add any number of elements to the linked list. So, the size of the linked list can be varied according to our needs.

All these reasons make linked lists more flexible to use. But linked lists are more complex to code compared to arrays.

This packet of code might help the programmers to implement stack and queue with the help of a linked list. I have used C++ for this and I would suggest you the same for better performance. However, I have attached the source code along with .exe files.

Download project

Reviews Report

Submitted by Gudipati Ganesh Yaswanth Kumar (GaneshGudipati)

Download packets of source code on Coders Packet