Showing posts from July, 2017

C++: Stack implementation using LinkedList (Data Structure)

We have already learnt about Stack in the post C++: Implementation of Stack using Array (Data Structure).  Now we are implementing Stack using Linked List which we have learnt in C++: Singly Linked List using Template (Data Structure). The C++ program for implementing Stack using Linked List is very simple. For push() and pop() function we have to use insert() and deleteNode() function from Linked List program.

C++: Doubly Linked List using Template (Data Structure)

A doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. It consists of an attribute key and two other pointer attributes: next and prev.The two node links allow traversal of the list in either direction. While adding or removing a node in a doubly linked list requires changing more links than the same operations on a singly linked list, the operations are simpler and potentially more efficient (for nodes other than first nodes) because there is no need to keep track of the previous node during traversal or no need to traverse the list to find the previous node, so that its link can be modified. I would recommend you to read C++: Singly Linked List using Template (Data Structure)Because some of the methods used in the program are explained in this post.

C++: Singly Linked List using Template (Data Structure)

A linked list is a data structure in which the objects are arranged in a linear order. Unlike an array, in which the linear order is determined by the array indices, the order in a linked list is determined by a pointer in each object. It has a group of nodes which together represents a sequence.  Under the simplest form, each node is composed of data and a reference (in other words, a link) to the next node in the sequence. 


C++: Understanding Template

C++’s class templates provide a better way to generate generic class declarations.Templates provide parameterized types—that is, they are capable of passing a type name as an argument to a recipe for building a class or a function. By feeding the type name int to a Queue template, for example, you can get the compiler to construct a Queue class for queuing ints.

Defining Template:
template <class Type>

C++: Implementation of Queue using Array (Data Structure)

I have studied the algorithm for implementation of Queue from Introduction to Algorithm.
Queue is one of the elementary data structure. And as I had said earlier to learn programming we have understand Data Structure and Algorithm. Any programming language is just a tool to solve a problem.


C++: Implementation of Stack using Array (Data Structure)

I have studied the algorithm for stack implementation from Introduction to Algorithm.
We all want to learn programming languages. It is not just to learn to code. It is understanding algorithms, data structures their relationships and implementing them using a computer programming language. Stack is one of the elementry data structure.


What is "namespace" and why do we use it?

What is namespace?"In general, a namespace is a container for a set of identifiers   Namespaces provide a level of direction to specific identifiers, thus  making it possible to distinguish between identifiers with the same  exact name. " Or According to Wikipedia “In computer programming namespaces are typically employed for the purpose of grouping symbols and identifiers around a particular functionality and to avoid name collisionsbetween multiple identifiers that share the same name.”

C++: Program to Add and Multiply the digits of a Number

We are the students of Computer Science and Engineering. We have to make many programs in various programming languages. We have to submit them in college assignment work or in school. Many times teacher just taught us the syntax of a language. The logic part has to be done on our own. I have written a post on it.How to improve logical thinking and problem solving skills?

C++ STL :Implementation of Counting sort (Sorting)

I have studied this algorithm from Introduction to Algorithm.

Counting sortassumes that each of the n input elements is an integer in the range 0 to k, for some integer k means the maximum element in the array must be equal to k.

C++: Implementation of Quicksort (Sorting)

I have studied this algorithm from Introduction to Algorithm and if you want to learn Data Structure and Algorithm I would strongly recommend this book.
Quicksort applies Divide and Conquer paradigm.
Divide: Partition the array A[p…r] into two subarrays A[p…q-1] and A[q+1…r] such that each element of A[p...q-1] is less than or equal to a[q] which is, in turn, less than or equal to each element of  A[q+1…r]
Conquer: Sort the two subarrays A[p…q-1] and A[q+1…r]by recursive calls to quicksort
Combine: Because the subarrays are already sorted, no work is needed to combine them the entire array A[p...r] is now sorted.

C++: Implementation of Heapsort (Sorting)

I have written this code after studying Heapsort algorithm from Introduction to Algorithm

max_heapify()function: The running time of this procedure is 
O(lg n) and it helps to maintain the max-heap property. Max-heap property means every node other than root node must be smaller than or equal to its parent.

build_max_heap()function: Its running time is O(n lg n). Result after execution ofbuild_max_heap() function is

Cool Websites you don't know about...

This website allows you to download research papers free of cost. If you are a student/researcher you must know about this.
Library Genesis
This is another great website for students. This website provide books for free. This is another type of search engine created by Google, students can search on it for school related stuff and find good results, there are also articles available there.
This amazing extension provides all the papers you need to read, for FREE!Available for Chrome and FireFox
50000 free ebooks to download (epub, kindle, android, ipad)
Old versions of Windows, Mac and Linux Software, Apps & Abandonware Games - Download at If you update or upgrade any software and if you don't like it; then you can downgrade

Check if the String is Palindrome (C++ & Java Program)

A palindrome string means the reverse of string is equal to the original string. 

C++ Program

#include <iostream>
#include <algorithm>
#include <string>

bool isPalindrome(const std::string& str)
   std::string temp(str);
   std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
   return temp == std::string(temp.rbegin(), temp.rend());

int main()
  std::string word;
  std::cout << "Enter the String \n";
  std::getline(std::cin, word);

    std::cout << "The string " << word << " is palindrome \n";
    std::cout << "The string " << word << " is not palindrome \n";
  return 0;

We have written #include <algorithm> beacuse we are using transform function which is in the Standard Template Library: Algorithm. You can know more about Transform from C++ STL : An example of Transform Algorithm.

We have written std::transform(temp.begin(), temp.end(…

C++ STL : An example of Transform Algorithm

#include <iostream>
#include <algorithm>
#include <list>

double reciprocal(double i){
  return 1.0/i;

int main()
    std::list<double> vals;
    int i;
    for(i=1; i<10; i++) vals.push_back((double)i);
    std::cout << "Original contents of vals:\n";
    std::list<double>::iterator p = vals.begin();
    while(p != vals.end()) {
    std::cout << *p << " ";
   std::cout << std::endl;

Popular Posts

C++: Breadth First Search program using Adjacency Matrix

Check if the String is Palindrome (C++ & Java Program)

C++: Depth First Search program using Adjacency Matrix (Graph Algorithm)