Showing posts with label Data Structures. Show all posts
Showing posts with label Data Structures. Show all posts

07 April, 2015

Data Stuctures : Implementation of Linked Lists using C++ (All Common Operations)

Linked Lists can get tricky sometimes and it took me some time to figure it out.

I have provided some of the common implementations of linked lists in the program given below and in no way is it a complete list!!
I have demonstrated
  • Insert and delete at head
  • Insert and delete at last
  • Insert and delete at a particular position
  • Reverse elements Iteratively and recursively (both)

12 February, 2015

Data Structures: Implementation of Stacks using linked lists in C++

Implementation of Stack Data Structure

 

Pre-requisites : 
  • A working knowledge of pointer operations 
  • Some idea about what a stack, linked list etc is
Stack is nothing but a list with the restriction that the operations can be performed only from one side, called "top".

Whatever the operation may be(insertion or deletion) has to be performed at the top.

You can visualize it as something like this.


06 February, 2015

Data Structures: Implementation of Linked Lists using Arrays in C++

Implementation of "Linked Lists" using Arrays


    To insert element at 
        
        
        1) 1st postition
        2) last position
        3) user defined position
   
    To delete element at
       
       1) 1st postition
       2) last position
       3) user defined position

05 February, 2015

Data Structures: Reverse elements of a Linked List in C++

In this post I will take you through about how
  • how to print the elements of a "Singly Linked List" using Iteration.
The prerequisite for this is that you should have an idea about how to
  • create a linked list(creating the structure).
  • Inserting elements in the linked list.
If you are new to the idea of linked lists.


I suggest you read Introduction to Linked Lists which will acquaint you with

  • what is a "linked list" and its advantages over arrays.
  • A C++ implementation of all the basic operations.

04 February, 2015

Data Structures: Linked List implementation in C++

Introduction to "Singly Linked Lists"

In this post I will be explaining about Singly liked lists.

Linked Lists are the simplest of the linear data structures. It manages to overcome some of the shortcomings of arrays, like
  • It is dynamic in contrast to arrays(also called as dense lists).
    We can modify the size of the list in the fly.
  • We don't have to specify the size of the linked list at the start like arrays.
But Linked lists has it's own dark side
  • To access an element in the linked list, we have to traverse the whole list. While in arrays, an element can be accessed in O(1). Let it be any element, at any index.