Showing posts from 2018

DS & A(Queue)

In this chapter, our topic of discussion will be the "Queue" Data Structure. But, before we get started, I would recommend you to read the previous chapters on Data Structures & Algorithms (especially the chapters on Array List, Linked List, Array Stack, and Linked Stack), that is in case it's your first time visiting my blog. Queue: Just like Stacks, Queues also are a restricted version of List but with a few minor differences compared to Stack. The following are some of the notable characteristics of a Queue:Data can only be inserted from the rear/back. Data insertion is referred to as ENQUEUE.Data can only be deleted from the front. Data deletion is referred to as DEQUEUE.Alternatively, ENQUEUE and DEQUEUE should always be executed on the opposite ends of the Queue.A Queue follows the FIFO(First In First Out)principle.The first and the last elements are referred to as FRONT and REAR respectively.

Visual Representation: Array-Based Queue: Pointer-Based(Linked) Queue: So…

DS & A(Stacks - Pointer Based)

In the previous chapter, we talked about Array Based Stacks so continuing our discussion on Stacks, In this chapter, we will see how to implement pointer-based Stacks also known as Linked Stacks.

Visual Representation:

Properties of Linked Stack:

Follows LIFO principle and all the other general properties of a stack.Unlike Array-based stack it's size is not fixed. Its size grows with the addition of new elements.A Linked Stack can have head and tail pointers but it is not mandatory. Stack ADT:

template<typename e> class Stack{public:    //Function to insert a value at the pop of the Stack    virtual bool push(const e& item) = 0;
    //Function to remove top-most Stack value    virtual bool pop(e& item) = 0;
    //Function to Display the stack    virtual void print() const= 0;};
Stack Implementation: Creating the Node: public:template<typename e>class Node{public:    e element;    Link<e>* next;
    Link(e elemValue = 0, Link<e>* nextValue = nullptr)    {      …

Share on Social Media