Latest From My Blog

Data Structure: Implementing Circular Queue in C++


Circular queue is a linear data structure. It follows FIFO principle. In circular queue the last node is connected back to the first node to make a circle. Circular linked list fallow the First In First Out principle. Elements are added at the rear end and the elements are deleted at front end of the queue.

This C++ Program demonstrates the implementation of Circular Queue.
Here is source code of the C++ Program to demonstrate the implementation of Circular Queue. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
 * C++ Program to Implement Circular Queue
 */
#include < iostream >
#define MAX 5
using namespace std;
/*
 * Class Circular Queue
 */
class Circular_Queue
{
    private:
        int *cqueue_arr;
        int front, rear;
    public:
        Circular_Queue()
        {
            cqueue_arr = new int [MAX];
            rear = front = -1;
        }
        /*
         * Insert into Circular Queue
         */
        void insert(int item)
        {
            if ((front == 0 && rear == MAX-1) || (front == rear+1))
            {
                cout << "Queue Overflow \n";
                return;
            }
            if (front == -1)
            {
                front = 0;
                rear = 0;
            }
            else
            {
                if (rear == MAX - 1)
                    rear = 0;
                else
                    rear = rear + 1;
            }
            cqueue_arr[rear] = item ;
        }
        /*
         * Delete from Circular Queue
         */
        void del()
        {
            if (front == -1)
            {
                cout << "Queue Underflow\n";
                return ;
            }
            cout << "Element deleted from queue is : " << cqueue_arr[front] << endl;
            if (front == rear)
            {
                front = -1;
                rear = -1;
            }
            else
            {
                if (front == MAX - 1)
                    front = 0;
                else
                    front = front + 1;
            }
        }
        /*
         * Display Circular Queue
         */
        void display()
        {
            int front_pos = front, rear_pos = rear;
            if (front == -1)
            {
                cout << "Queue is empty\n";
                return;
            }
            cout << "Queue elements :\n";
            if (front_pos <= rear_pos)
            {
                while (front_pos <= rear_pos)
                {
                    cout<> choice;
        switch(choice)
        {
        case 1:
            cout << "Input the element for insertion in queue : ";
            cin >> item;	
            cq.insert(item);
	    break;
	case 2:
            cq.del();
	    break;
        case 3:
            cq.display();
	    break;
	case 4:
	    break;
	default:
	    cout << "Wrong choice\n";
	}/*End of switch*/
    }
    while(choice != 4);
    return 0;
}

Output
$ g++ circular_queue.cpp
$ a.out
 
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the element for insertion in queue : 3
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the element for insertion in queue : 2
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the element for insertion in queue : 6
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the element for insertion in queue : 4
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the element for insertion in queue : 1
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 3
Queue elements :
3  2  6  4  1
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 2
Element deleted from queue is : 3
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 3
Queue elements :
2  6  4  1
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 4
 
------------------
(program exited with code: 1)
Press return to continue

Data Structure: Implementing Priority Queue in C++


A priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue.
More info: Wikipedia Link

This C++ Program demonstrates the implementation of Priority Queue.
Here is source code of the C++ Program to demonstrate the implementation of Priority Queue. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
 * C++ Program to Implement Priority Queue
 */
#include < iostream >
#include < cstdio >
#include < cstring >
#include < cstdlib >
using namespace std;
 
/*
 * Node Declaration
 */
struct node
{
 int priority;
 int info;
 struct node *link;
};
/*
 * Class Priority Queue
 */
class Priority_Queue
{
    private:
        node *front;
    public:
        Priority_Queue()
        {
            front = NULL;
        }
        /*
         * Insert into Priority Queue
         */
        void insert(int item, int priority)
        {
            node *tmp, *q;
            tmp = new node;
            tmp->info = item;
            tmp->priority = priority;
            if (front == NULL || priority < front->priority)
            {
                tmp->link = front;
                front = tmp;
            }
            else
            {
                q = front;
                while (q->link != NULL && q->link->priority <= priority)
                    q=q->link;
                tmp->link = q->link;
                q->link = tmp;
            }
        }
        /*
         * Delete from Priority Queue
         */
        void del()
        {
            node *tmp;
            if(front == NULL)
                cout << "Queue Underflow\n";
            else
            {
                tmp = front;
                cout << "Deleted item is: " << tmp->info << endl;
                front = front->link;
                free(tmp);
            }
        }
        /*
         * Print Priority Queue
         */
        void display()
        {
            node *ptr;
            ptr = front;
            if (front == NULL)
                cout << "Queue is empty\n";
            else
            { cout << "Queue is :\n";
                cout << "Priority       Item\n";
                while(ptr != NULL)
                {
                    cout << ptr->priority << "                 " << ptr->info << endl;
                    ptr = ptr->link;
                }
            }
        }
};
/*
 * Main
 */
int main()
{
    int choice, item, priority;
    Priority_Queue pq; 
    do
    {
        cout << "1.Insert\n";
        cout << "2.Delete\n";
        cout << "3.Display\n";
        cout << "4.Quit\n";
        cout << "Enter your choice : "; 
        cin >> choice;
        switch(choice)
        {
        case 1:
            cout << "Input the item value to be added in the queue : ";
            cin >> item;
            cout << "Enter its priority : ";
            cin >> priority;
            pq.insert(item, priority);
            break;
        case 2:
            pq.del();
            break;
        case 3:
            pq.display();
            break;
        case 4:
            break;
        default :
            cout << "Wrong choice\n";
        }
    }
    while(choice != 4);
    return 0;
}
Output
$ g++ priority_queue.cpp
$ a.out
 
4.Quit
Enter your choice : 1
Input the item value to be added in the queue : 4
Enter its priority : 2
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the item value to be added in the queue : 3
Enter its priority : 3
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the item value to be added in the queue : 2
Enter its priority : 4
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the item value to be added in the queue : 1
Enter its priority : 5
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 3
Queue is :
Priority       Item
1                 5
2                 4
3                 3
4                 2
5                 1
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 2
Deleted item is: 5
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 3
Queue is :
Priority       Item
2                 4
3                 3
4                 2
5                 1
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 4
 
------------------
(program exited with code: 1)
Press return to continue

Data Structure: Binary Search Tree


Until now all data structures that we have covered (Stack,Queue,Linked List) are linear in nature ie. they have a definite order of placement. Now we shall study Binary Trees which requires a different thought process as it is a non linear data structure.

A Binary Tree consists of a main node known as the Root. The Root then has two sub-sections, ie. the left and the right half. The data subsequently stored after the root is created depends on it's value compared to the root. Suppose the root value is 10 and the Value to be added is 15, then the data is added to the right section of the root. The Basic idea is that every node can be thought of a binary tree itself. Each node has two pointers, one to the left and the other to the right. Depending on the value to be stored, it is placed after a node's right pointer if the value of the node is lesser than the one to be added or the node's left pointer if vice versa.

Let's take an Example. To add the Following List of Numbers, we end up with a Binary Tree like this:

32 16 34 1 87 13 7 18 14 19 23 24 41 5 53

Here's How:
**: KEEP ADDING DATA IN THE TREE ON PAPER AFTER EACH STEP BELOW TO UNDERSTAND HOW THE TREE IS FORMED.
(1). Since 32 is the First Number to be added, 32 becomes the root of the tree. 
(2). Next Number is 16 which is lesser than 32 Hence 16 becomes left node of 32.
(3). 34. Since 34 > 32 , 34 becomes the right node of the ROOT.
(4). 1. Since 1 < 32 we jump to the left node of the ROOT. But since the left node
has already been taken we test 1 once again. Since 1 < 16, 1 becomes the left
node of 16.
(5). 87. Since 87 > 32 we jump to the right node of the root. Once again this
space is occupied by 34. Now since 87 > 34, 87 becomes the right node of 34.
(6). 13. Since 13 < 32 we jump to left node of the root. There, 13 < 16 so we
continue towards the left node of 16. There 13 > 1, so 13 becomes the right
node of 1.
(7). Similarly work out addition till the end ie. before Number 53.
(8). 53. Since 53 > 32 we jump to the right node of the root. There 53 > 34 so we
continue to the right node of 34. There 53 < 87 so we continue towards the
left node of 87. There 53 > 41 so we jump to the right node of 41. Since the
Right node of 41 is empty 53 becomes the right node of 41.

This should give you an idea of how a Binary Tree works. You must know that:
(1). The linking of nodes to nodes in a Binary Tree is one to one in nature
ie. a node cannot be pointed by more than 1 node.
(2). A Node can point to two different sub-nodes at the most.
Here in the binary tree above there are a few nodes whose left and right
pointers are empty ie. they have no sub-node attached to them. So Nodes 5,14,18,
19,23,24,41 have their left nodes empty.

There are three popular ways to display a Binary Tree. Displaying the trees contents is known as transversal. There are three ways of transversing a tree iw. in inorder, preorder, and postorder transversal methods. Description of each is shown below:

PREORDER:
  • Visit the root.
  • Transverse the left leaf in preorder.
  • Transverse the right leaf in preorder.
INORDER:
  • Transverse the left leaf in inorder.
  • Visit the root.
  • Transverse the right leaf in inorder.
POSTORDER:
  • Transverse the left leaf in postorder.
  • Transverse the right leaf in postorder.
  • Visit the root.


Writing code for these three methods are simple if we understand the recursive nature of a binary tree. Binary tree is recursive, as in each node can be thought of a binary tree itself. It's just the order of displaying data that makes a difference for transversal.

Deletion from a Binary Tree is a bit more difficult to understand. For now just remember that for deleting a node, it is replaced with it's next inorder successor. I'll explain everything after the Binary Tree code. Now that you've got all your Binary Tree Fundas clear, let's move on with the Source code.


#include < iostream >

using namespace std;

#define YES 1
#define NO 0

class tree
{
	private:
		struct leaf
		{
			int data;
			leaf *l;
			leaf *r;
		};
		struct leaf *p;

	public:
		tree();
		~tree();
		void destruct(leaf *q);
		tree(tree& a);
		void findparent(int n,int &found,leaf* &parent);
		void findfordel(int n,int &found,leaf *&parent,leaf* &x);
		void add(int n);
		void transverse();
		void in(leaf *q);
		void pre(leaf *q);
		void post(leaf *q);
		void del(int n);
};
		
tree::tree()
{
	p=NULL;
}

tree::~tree()
{
	destruct(p);
}

void tree::destruct(leaf *q)
{
	if(q!=NULL)
	{
		destruct(q->l);
		del(q->data);
		destruct(q->r);
	}
}
void tree::findparent(int n,int &found,leaf *&parent)
{
	leaf *q;
	found=NO;
	parent=NULL;

	if(p==NULL)
		return;

	q=p;
	while(q!=NULL)
	{
		if(q->data==n)
		{
			found=YES;
			return;
		}
		if(q->data > n)
		{
			parent=q;
			q=q->l;
		}
		else
		{
			parent=q;
			q=q->r;
		}
	}
}

void tree::add(int n)
{
	int found;
	leaf *t,*parent;
	findparent(n,found,parent);
	if(found==YES)
		cout << "\nSuch a Node Exists";
	else
	{
		t=new leaf;
		t->data=n;
		t->l=NULL;
		t->r=NULL;

		if(parent==NULL)
			p=t;
		else
			parent->data > n ? parent->l=t : parent->r = t;
	}
}

void tree::transverse()
{
	int c;
	cout << "\n1.InOrder\n2.Preorder\n3.Postorder\nChoice: ";
	cin >> c;
	switch(c)
	{
		case 1:
			in(p);
			break;

		case 2:
			pre(p);
			break;

		case 3:
			post(p);
			break;
	}
}

void tree::in(leaf *q)
{
	if(q!=NULL)
	{
		in(q->l);
		cout << "\t"<data<r);
	}
	
}

void tree::pre(leaf *q)
{
	if(q!=NULL)
	{
		cout << "\t"<data<l);
		pre(q->r);
	}
	
}

void tree::post(leaf *q)
{
	if(q!=NULL)
	{
		post(q->l);
		post(q->r);
		cout << "\t"<data<data==n)
		{
			found=1;
			x=q;
			return;
		}
		if(q->data>n)
		{
			parent=q;
			q=q->l;
		}
		else
		{
			parent=q;
			q=q->r;
		}
	}
}

void tree::del(int num)
{
	leaf *parent,*x,*xsucc;
	int found;

	// If EMPTY TREE
	if(p==NULL)
	{
		cout << "\nTree is Empty";
		return;
	}
	parent=x=NULL;
	findfordel(num,found,parent,x);
	if(found==0)
	{
		cout<<"\nNode to be deleted NOT FOUND";
		return;
	}

	// If the node to be deleted has 2 leaves
	if(x->l != NULL && x->r != NULL)
	{
		parent=x;
		xsucc=x->r;

		while(xsucc->l != NULL)
		{
			parent=xsucc;
			xsucc=xsucc->l;
		}
		x->data=xsucc->data;
		x=xsucc;
	}

	// if the node to be deleted has no child
	if(x->l == NULL && x->r == NULL)
	{
		if(parent->r == x)
			parent->r=NULL;
		else
			parent->l=NULL;

		delete x;
		return;
	}

	// if node has only right leaf
	if(x->l == NULL && x->r != NULL )
	{
		if(parent->l == x)
			parent->l=x->r;
		else
			parent->r=x->r;

		delete x;
		return;
	}

	// if node to be deleted has only left child
	if(x->l != NULL && x->r == NULL)
	{
		if(parent->l == x)
			parent->l=x->l;
		else
			parent->r=x->l;

		delete x;
		return;
	}
}

int main()
{
	tree t;
	int data[]={32,16,34,1,87,13,7,18,14,19,23,24,41,5,53};
	for(int iter=0 ; iter < 15 ; i++)
		t.add(data[iter]);

	t.transverse();
	t.del(16);
	t.transverse();
	t.del(41);
	t.transverse();
	return 0;
}

Output
1.InOrder
2.Preorder
3.Postorder
Choice: 1
1
5
7
13
14
16
18
19
23
24
32
34
41
53
87

1.InOrder
2.Preorder
3.Postorder
Choice: 2
32
18
1
13
7
5
14
19
23
24
34
87
41
53

1.InOrder
2.Preorder
3.Postorder
Choice: 3
5
7
14
13
1
24
23
19
18
53
87
34
32
Press any key to continue


NOTE: Visual C++ may give Runtime Errors with this code. Compile with Turbo C++.

Just by looking at the output you might realise that we can print out the whole tree in ascending order by using inorder transversal. Infact Binary Trees are used for Searching [ Binary Search Trees {BST} ] as well as in Sorting. The Addition of data part seems fine. Only the deletion bit needs to be explained.

For deletion of data there are a few cases to be considered:
1. If the leaf to be deleted is not found.
2. If the leaf to be deleted has no sub-leafs.
3. If the leaf to be deleted has 1 sub-leaf.
4. If the leaf to be deleted has 2 sub-leafs.

CASE 1:
Dealing with this case is simple, we simply display an error message.

CASE 2:
Since the node has no sub-nodes, the memory occupied by this should be freed and either the left link or the right link of the parent of this node should be set to NULL. Which of these should be set to NULL depends upon whether the node being deleted is a left child or a right child of its parent.

CASE 3:
In the third case we just adjust the pointer of the parent of the leaf to be deleted such that after deletion it points to the child of the node being deleted.

CASE 4:
The last case in which the leaf to be deleted has to sub-leaves of its own is rather complicated.The whole logic is to locate the inorder successor, copy it's data and reduce the problem to simple deletion of a node with one or zero leaves. Consider in the above program...(Refer to the previous tree as well) when we are deleting 16 we search for the next inorder successor. So we simply set the data value to 5 and delete the node with value 5 as shown for cases 2 and 3.

Programming: Cpp Program to Implement Queue Using Linked Lists


This C++ program, using iteration, implements the list of elements removed from the queue in first in first out mode using a linked list. A linked list is an ordered set of data elements, each containing a link to its successor.

Here is the source code of the C program to display the list of elements removed from the queue. The C++ program is successfully compiled and run on DevCpp, a C++ compiler. The program output is also shown below.

/*
 * C++ Program to Implement Queue using Linked List
 */
#include < iostream >
#include < stdio.h >
#include < conio.h >
using namespace std;
struct node
{
    int data;
    node *next;
}*front = NULL,*rear = NULL,*p = NULL,*np = NULL;
void push(int x)
{
    np = new node;
    np->data = x;
    np->next = NULL;
    if(front == NULL)
    {
        front = rear = np;
        rear->next = NULL;
    }
    else
    {
        rear->next = np;
        rear = np;
        rear->next = NULL;
    }
}
int remove()
{
    int x;
    if(front == NULL)
    {
        cout << "empty queue\n";
    }
    else
    {
        p = front;
        x = p->data;
        front = front->next;
        delete(p);
        return(x);
    }
}
int main()
{
    int n,c = 0,x;
    cout << "Enter the number of values to be pushed into queue\n";
    cin >> n;
    while (c < n)
    {
 cout << "Enter the value to be entered into queue\n";
 cin >> x;
        push(x);
        c++;
     }
     cout << "\n\nRemoved Values\n\n";
     while(true)
     {
        if (front != NULL)
            cout << remove() << endl;
        else
            break;
     }
     getch();
}

Output of above program
Output
Enter the number of values to be pushed into queue
6
Enter the value to be entered into queue
5
Enter the value to be entered into queue
4
Enter the value to be entered into queue
3
Enter the value to be entered into queue
2
Enter the value to be entered into queue
1
Enter the value to be entered into queue
0
 
Removed Values
 
5
4
3
2
1
0

Programming: C++ Program to Implement Stack Using Linked List

This C++ program, using iteration, implements the list of elements removed from the stack in last in first out mode using a linked list. A linked list is an ordered set of data elements, each containing a link to its successor.


Here is the source code of the C++ program to display the list of elements removed from the stack. The C++ program is successfully compiled and run on DevCpp, a C++ compiler. The program output is also shown below.

*
 * C++ Program to Implement Queue using Linked List
 */
#include < iostream >
#include < stdio.h >
#include < conio.h >
using namespace std;
struct node
{
    int data;
    node *next;
}*front = NULL, *rear = NULL, *p = NULL, *np = NULL;
void push(int x)
{
    np = new node;
    np->data = x;
    np->next = NULL;
    if(front == NULL)
    {
        front = rear = np;
        rear->next = NULL;
    }
    else
    {
        rear->next = np;
        rear = np;
        rear->next = NULL;
    }
}
int remove()
{
    int x;
    if (front == NULL)
    {
        cout << "empty queue\n";
    }
    else
    {
        p = front;
        x = p->data;
        front = front->next;
        delete(p);
        return(x);
    }
}
int main()
{
    int n, c = 0, x;
    cout << "Enter the number of values to be pushed into queue\n";
    cin >> n;
    while (c < n)
    {
 cout << "Enter the value to be entered into queue\n";
 cin >> x;
        push(x);
        c++;
    }
    cout << "\n\nRemoved Values\n\n";
    while(true)
    {
        if (front != NULL)
            cout << remove() << endl;
 else
     break;
    }
    getch();
}

Here is the output of the program:
Output
Enter the number of values to be pushed into queue
6
Enter the value to be entered into queue
5
Enter the value to be entered into queue
4
Enter the value to be entered into queue
3
Enter the value to be entered into queue
2
Enter the value to be entered into queue
1
Enter the value to be entered into queue
0
 
Removed Values
 
5
4
3
2
1
0

Programming: C++ program to implement Heap

A heap is a partially sorted binary tree. Although a heap is not completely in order, it conforms to a sorting principle: every node has a value less (for the sake of simplicity, we will assume that all orderings are from least to greatest) than either of its children. Additionally, a heap is a "complete tree" -- a complete tree is one in which there are no gaps between leaves. For instance, a tree with a root node that has only one child must have its child as the left node. More precisely, a complete tree is one that has every level filled in before adding a node to the next level, and one that has the nodes in a given level filled in from left to right, with no breaks.


Why use a heap?

A heap can be thought of as a priority queue; the most important node will always be at the top, and when removed, its replacement will be the most important. This can be useful when coding algorithms that require certain things to processed in a complete order, but when you don't want to perform a full sort or need to know anything about the rest of the nodes. For instance, a well-known algorithm for finding the shortest distance between nodes in a graph, Dijkstra's Algorithm, can be optimized by using a priority queue.

C++ Implementation of Heap


 
/*
 * C++ Program to Implement Heap
 */
#include < iostream >
#include < cstdlib >
#include < vector >
#include < iterator >
using namespace std;
/*
 * Class Declaration
 */
class Heap
{
    private:
        vector < int > heap;
        int left(int parent);
        int right(int parent);
        int parent(int child);
        void heapifyup(int index);
        void heapifydown(int index);
    public:
        Heap()
        {}
        void Insert(int element);
        void DeleteMin();
        int ExtractMin();
        void DisplayHeap();
        int Size();
};

/*
 * Return Heap Size
 */
int Heap::Size()
{
    return heap.size();
}
 
/*
 * Insert Element into a Heap
 */
void Heap::Insert(int element)
{
    heap.push_back(element);
    heapifyup(heap.size() -1);
}
/*
 * Delete Minimum Element
 */
void Heap::DeleteMin()
{
    if (heap.size() == 0)
    {
        cout << "Heap is Empty" << endl;
        return;
    }
    heap[0] = heap.at(heap.size() - 1);
    heap.pop_back();
    heapifydown(0);
    cout << "Element Deleted" << endl;
}
 
/*
 * Extract Minimum Element
 */
int Heap::ExtractMin()
{
    if (heap.size() == 0)
    {
        return -1;
    }
    else
        return heap.front();
}
 
/*
 * Display Heap
 */
void Heap::DisplayHeap()
{
    vector < int >::iterator pos = heap.begin();
    cout << "Heap -->  ";
    while (pos != heap.end())
    {
        cout << *pos << " ";
        pos++;
    }
    cout << endl;
}
 
/*
 * Return Left Child
 */
int Heap::left(int parent)
{
    int l = 2 * parent + 1;
    if(l < heap.size())
        return l;
    else
        return -1;
}
 
/*
 * Return Right Child
 */
int Heap::right(int parent)
{
    int r = 2 * parent + 2;
    if(r < heap.size())
        return r;
    else
        return -1;
}
 
/*
 * Return Parent
 */
int Heap::parent(int child)
{
    int p = (child - 1)/2;
    if(child == 0)
        return -1;
    else
        return p;
}
 
/*
 * Heapify- Maintain Heap Structure bottom up
 */
void Heap::heapifyup(int in)
{
    if (in >= 0 && parent(in) >= 0 && heap[parent(in)] > heap[in])
    {
        int temp = heap[in];
        heap[in] = heap[parent(in)];
        heap[parent(in)] = temp;
        heapifyup(parent(in));
    }
}
 
/*
 * Heapify- Maintain Heap Structure top down
 */
void Heap::heapifydown(int in)
{
 
    int child = left(in);
    int child1 = right(in);
    if (child >= 0 && child1 >= 0 && heap[child] > heap[child1])
    {
       child = child1;
    }
    if (child > 0)
    {
        int temp = heap[in];
        heap[in] = heap[child];
        heap[child] = temp;
        heapifydown(child);
    }
}
 
/*
 * Main Contains Menu
 */
int main()
{
    Heap h;
    while (1)
    {
        cout << "------------------" << endl;
        cout << "Operations on Heap" << endl;
        cout << "------------------" << endl;
        cout << "1.Insert Element" << endl;
        cout << "2.Delete Minimum Element" << endl;
        cout << "3.Extract Minimum Element" << endl;
        cout << "4.Print Heap" << endl;
        cout << "5.Exit" << endl;
        int choice, element;
        cout<<"Enter your choice: ";
        cin>>choice;
        switch(choice)
        {
        case 1:
            cout << "Enter the element to be inserted: ";
            cin >> element;
            h.Insert(element);
            break;
        case 2:
            h.DeleteMin();
            break;
        case 3:
            cout << "Minimum Element: ";
            if (h.ExtractMin() == -1)
            {
                cout << "Heap is Empty" << endl;
            }
            else
                cout << "Minimum Element:  " << h.ExtractMin() << endl;
            break;
        case 4:
            cout << "Displaying elements of Hwap:  ";
            h.DisplayHeap();
            break;
        case 5:
            exit(1);
        default:
            cout << "Enter Correct Choice" << endl;
        }
    }
    return 0;
}

Output of the above program:

$ g++ heap.cpp
$ a.out
/*
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 1
Enter the element to be inserted: 7
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  7
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 1
Enter the element to be inserted: 4
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  4 7
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 1
Enter the element to be inserted: 9
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  4 7 9
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 1
Enter the element to be inserted: 3
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  3 4 9 7
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 3
Minimum Element: Minimum Element:  3
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 1
Enter the element to be inserted: 5
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  3 4 9 7 5
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 1
Enter the element to be inserted: 11
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  3 4 9 7 5 11
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 1
Enter the element to be inserted: 2
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  2 4 3 7 5 11 9
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 2
Element Deleted
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  3 4 11 7 5 9
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 3
Minimum Element: Minimum Element:  3
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 2
Element Deleted
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 4
Displaying elements of Hwap:  Heap -->  4 5 11 7 9
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 3
Minimum Element: Minimum Element:  4
------------------
Operations on Heap
------------------
1.Insert Element
2.Delete Minimum Element
3.Extract Minimum Element
4.Print Heap
5.Exit
Enter your choice: 5
 
------------------
(program exited with code: 0)
Press return to continue

Programming: C++ Program to Implement Hash Table

What is hash table ?
Do not confuse this with Hash List or Hash Tree.
From Wikipedia about hash table

In computing, a hash table (hash map) is a data structure used to implement an associative array, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.

Ideally, the hash function will assign each key to a unique bucket, but it is possible that two keys will generate an identical hash causing both keys to point to the same bucket. Instead, most hash table designs assume that hash collisions—different keys that are assigned by the hash function to the same bucket—will occur and must be accommodated in some way.


This C++ Program demonstrates operations on Hash Tables

Here is source code of the C++ Program to demonstrate Hash Tables. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.


/*
 *C++ Program to Implement Hash Tables
 */
#include
#include
#include
#include
using namespace std;
const int TABLE_SIZE = 128;
 
/*
 * HashEntry Class Declaration
 */
class HashEntry
{
    public:
        int key;
        int value;
        HashEntry(int key, int value)
        {
            this->key = key;
            this->value = value;
        }
};
 
/*
 * HashMap Class Declaration
 */
class HashMap
{
    private:
        HashEntry **table;
    public:   
        HashMap()
	{
            table = new HashEntry * [TABLE_SIZE];
            for (int i = 0; i< TABLE_SIZE; i++)
            {
                table[i] = NULL;
            }
        }
        /*
         * Hash Function
         */
        int HashFunc(int key)
        {
            return key % TABLE_SIZE;
        }
        /*
         * Insert Element at a key
         */
	void Insert(int key, int value)
	{
            int hash = HashFunc(key);
            while (table[hash] != NULL && table[hash]->key != key)
            {
                hash = HashFunc(hash + 1);
            }
            if (table[hash] != NULL)
                delete table[hash];
            table[hash] = new HashEntry(key, value);
	}
        /*
         * Search Element at a key
         */
        int Search(int key)
	{
	    int  hash = HashFunc(key);
	    while (table[hash] != NULL && table[hash]->key != key)
	    {
	        hash = HashFunc(hash + 1);
	    }
	    if (table[hash] == NULL)
	        return -1;
	    else
	        return table[hash]->value;
        }
 
        /*
         * Remove Element at a key
         */
        void Remove(int key)
	{
	    int hash = HashFunc(key);
	    while (table[hash] != NULL)
	    {
	        if (table[hash]->key == key)
	            break;
	        hash = HashFunc(hash + 1);
	    }
            if (table[hash] == NULL)
	    {
                cout<<"No Element found at key "<>choice;
        switch(choice)
        {
        case 1:
            cout<<"Enter element to be inserted: ";
            cin>>value;
            cout<<"Enter key at which element to be inserted: ";
            cin>>key;
            hash.Insert(key, value);
            break;
        case 2:
            cout<<"Enter key of the element to be searched: ";
            cin>>key;
            if (hash.Search(key) == -1)
            {
	        cout<<"No element found at key "<>key;
            hash.Remove(key);
            break;
        case 4:
            exit(1);
        default:
           cout<<"\nEnter correct option\n";
       }
    }
    return 0;
}

$ g++ hash_table.cpp
$ a.out
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 1
Enter element to be inserted: 12
Enter key at which element to be inserted: 1
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 1
Enter element to be inserted: 24
Enter key at which element to be inserted: 2
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 1
Enter element to be inserted: 36
Enter key at which element to be inserted: 3
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 1
Enter element to be inserted: 48
Enter key at which element to be inserted: 4
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 1
Enter element to be inserted: 60
Enter key at which element to be inserted: 5
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 2
Enter key of the element to be searched: 3
Element at key 3 : 36
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 2
Enter key of the element to be searched: 5
Element at key 5 : 60
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 3
Enter key of the element to be deleted: 4
Element Deleted
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 2
Enter key of the element to be searched: 4
No element found at key 4
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 2
Enter key of the element to be searched: 2
Element at key 2 : 24
 
----------------------
Operations on Hash Table
 
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Exit
Enter your choice: 4
 
 
------------------
(program exited with code: 1)
Press return to continue

Programming: C Program to Represent Graph Using Adjacency Matrix

This C program generates graph using Adjacency Matrix Method.

A graph G,consists of two sets V and E. V is a finite non-empty set of vertices.E is a set of pairs of vertices,these pairs are called as edges V(G) and E(G) will represent the sets of vertices and edges of graph G.

Undirected graph – It is a graph with V vertices and E edges where E edges are undirected. In undirected graph, each edge which is present between the vertices Vi and Vj,is represented by using a pair of round vertices (Vi,Vj).

Directed graph – It is a graph with V vertices and E edges where E edges are directed.In directed graph,if Vi and Vj nodes having an edge.than it is represented by a pair of triangular brackets Vi,Vj.

Here is the source code of the C program to create a graph using adjacency matrix. The C program is successfully compiled and run on a Linux system. The program output is also shown below.


//... A Program to represent a Graph by using an Adjacency Matrix method
#include 
#include 
int dir_graph();
int undir_graph();
int read_graph(int adj_mat[50][50], int n );

void main()
{
   int option;
   do
   {     
        printf("\n A Program to represent a Graph by using an ");
  printf("Adjacency Matrix method \n ");
  printf("\n 1. Directed Graph ");
  printf("\n 2. Un-Directed Graph ");
  printf("\n 3. Exit ");
  printf("\n\n Select a proper option : ");
  scanf("%d", &option);
  switch(option)
  {
    case 1 : dir_graph();
       break;
    case 2 : undir_graph();
       break;
    case 3 : exit(0);
  } // switch
    }while(1);
}
 
int dir_graph()
{
    int adj_mat[50][50];
    int n;
    int in_deg, out_deg, i, j;
    printf("\n How Many Vertices ? : ");
    scanf("%d", &n);
    read_graph(adj_mat, n);
    printf("\n Vertex \t In_Degree \t Out_Degree \t Total_Degree ");
    for (i = 1; i <= n ; i++ )
    {
        in_deg = out_deg = 0;
 for ( j = 1 ; j <= n ; j++ )
 {
            if ( adj_mat[j][i] == 1 )
                in_deg++;
 } 
        for ( j = 1 ; j <= n ; j++ )
            if (adj_mat[i][j] == 1 )
                out_deg++;
            printf("\n\n %5d\t\t\t%d\t\t%d\t\t%d\n\n",i,in_deg,out_deg,in_deg+out_deg);
    }
    return;
}
 
int undir_graph()
{
    int adj_mat[50][50];
    int deg, i, j, n;
    printf("\n How Many Vertices ? : ");
    scanf("%d", &n);
    read_graph(adj_mat, n);
    printf("\n Vertex \t Degree ");
    for ( i = 1 ; i <= n ; i++ )
    {
        deg = 0;
        for ( j = 1 ; j <= n ; j++ )
            if ( adj_mat[i][j] == 1)
                deg++;
        printf("\n\n %5d \t\t %d\n\n", i, deg);
    } 
    return;
} 
 
int read_graph ( int adj_mat[50][50], int n )
{
    int i, j;
    char reply;
    for ( i = 1 ; i <= n ; i++ )
    {
        for ( j = 1 ; j <= n ; j++ )
        {
            if ( i == j )
            {
                adj_mat[i][j] = 0;
  continue;
            } 
            printf("\n Vertices %d & %d are Adjacent ? (Y/N) :",i,j);
            scanf("%c", &reply);
            if ( reply == 'y' || reply == 'Y' )
                adj_mat[i][j] = 1;
            else
                adj_mat[i][j] = 0;
 }
    } 
    return;
}

$ gcc graph.c -o graph
$ ./graph
 A Program to represent a Graph by using an Adjacency Matrix method 
 
 1. Directed Graph 
 2. Un-Directed Graph 
 3. Exit 
 
 Select a proper option : 
 How Many Vertices ? : 
 Vertices 1 & 2 are Adjacent ? (Y/N) : N
 Vertices 1 & 3 are Adjacent ? (Y/N) : Y
 Vertices 1 & 4 are Adjacent ? (Y/N) : Y
 Vertices 2 & 1 are Adjacent ? (Y/N) : Y
 Vertices 2 & 3 are Adjacent ? (Y/N) : Y
 Vertices 2 & 4 are Adjacent ? (Y/N) : N
 Vertices 3 & 1 are Adjacent ? (Y/N) : Y
 Vertices 3 & 2 are Adjacent ? (Y/N) : Y
 Vertices 3 & 4 are Adjacent ? (Y/N) : Y
 Vertices 4 & 1 are Adjacent ? (Y/N) : Y
 Vertices 4 & 2 are Adjacent ? (Y/N) : N
 Vertices 4 & 3 are Adjacent ? (Y/N) : Y
 Vertex   In_Degree   Out_Degree   Total_Degree 
 
     1   2  0  2
 
 
 
     2   1  2  3
 
 
 
     3   0  1  1
 
 
 
     4   1  1  2
 
 
 A Program to represent a Graph by using an Adjacency Matrix method 
 
 1. Directed Graph 
 2. Un-Directed Graph 
 3. Exit

What is the difference between VoIP and VoLTE?

VoIP refers to Voice Over IP, which is a methodology of delivering the voice communication data over the internet. Voice over IP (VoIP) refers to sending voice data over the internet. Initially this was only possible using computers (connected or WiFi). An example would be Skype. 

With mobile phones becoming popular (pre-smartphone mostly but also some smartphones) there was an attempt to port VoIP over mobile phones and this was generally referred to as mobile VoIP (mVoIP). You could use cellular data connectivity or WiFi for VoIP in this case. Nowadays, VoIP is referred for Over The Top (OTT) applications that may use PC's, tablets, smartphones, etc. Example would be Skype, Viber, WhatsApp, etc.

Packets are packets and the only thing that knows they are voice is the application that receives than & processes them eg your Skype app. As such that is Layer 7 and they go through L1-L6 exactly as every other packet. They could be going over LTE, over WiFi or over ADSL - it doesn't matter = packets are packets.

The cellular world used to have 2 separate core networks called CS (circuit switched) that was used for voice and PS (packet switched) for data. To simplify the network, they started moving Voice over to PS part. For 3G/HSPA this became known as VoHSPA (Voice over HSPA) and for 4G/LTE it is known as VoLTE (Voice over LTE). Since HSPA/LTE is data only network, the networks realised that they can use WiFi for the access network in the same way. Hence VoWiFi is using WiFi for access but the PS network for guaranteeing the quality of service (QoS). 


The Voice over LTE, VoLTE scheme was devised as a result of operators seeking a standardised system for transferring traffic for voice over LTE. Originally LTE was seen as a completely IP cellular system just for carrying data, and operators would be able to carry voice either by reverting to 2G / 3G systems or by using VoIP in one form or another.

VoLTE is a specific type of VoIP designed into the LTE standard, so it has lots of very specific optimisations and accelerations.  In effect, the packets are treated as "special" by the whole LTE network. 

That means it will work better (lower latency, less power, etc) - and as you say, be able to handover to other LTE cells or to 3G/2G legacy networks.

Signals Research Group (very good, very respected consultancy) & Spirent did some testing and confirmed this.

Commercially deployed Voice-over-LTE (VoLTE) technology provides better service than 3G Circuit Switched (CS) voice and Internet calling services and Skype software.
The analysis found that VoLTE users enjoyed considerably better call quality, faster connectivity and substantially less drain on the batteries of their mobile devices. 

The report evaluates several attributes including call setup time, call reliability, call quality, network resource requirements, and the impact on battery life. The report’s highlights include:
      • VoLTE call quality greatly exceeded that of 3G CS voice and was measurable higher than the HD voice service offered by Skype
      • With network loading, and in particular with background applications running on the mobile phone and transferring data with the network, the VoLTE results were considerably better than Skype
      • VoLTE call setup time was nearly twice as fast as 3G Circuit Switched Fallback (CSFB) call setup
      • VoLTE used substantially fewer network resources than Skype voice, which in turn resulted in longer estimated device battery life for the subscriber and a more efficient network for the operator
      • When leaving LTE coverage, VoLTE calls were successfully handed over to 3G CS voice. The network’s enhanced Single Radio Voice Call Continuity ensures calls continue without interruption
“The clear choice for mobile network operators should be a no brainer,” said Emil Olbrich, vice president of Network Technologies for SRG. “VoLTE delivers a consistently higher call quality than OTT voice applications. Operators should also strongly consider the long-term network savings associated with VoLTE, given that it takes advantage of advanced features that allow it to use far less network resources when it comes to supporting a voice call when compared with current OTT voice applications.” 


So how do you compare VoLTE, VoWiFi and VoIP. I found this interesting table



As can be seen in the table, VoLTE should provide you the best quality, followed by VoWiFi (SIP VoIP) and VoIP would be the worst. Again, the worst may still be good enough for most people most of the time.

Knowledge: Some good computer tricks 2

1. Some trick for Gmail users

To open only unread emails , just type is:unread in search box.
You can also open is:starred , is:read , is:muted , is:chat.


if you want to open unread emails from inbox only then type
is:unread label:inbox  in search box.




For other labels just use label:spam , label:chats e.t.c  and You can combine the keywords according to use.

2. How to enable GodMode on Windows. 

This is a very simple trick.
a. In any drive of your computer create a New Folder and rename it as GodMode.


b. Now append the string (without quotes) “.{ED7BA470-8E54-465E-825C-99712043E01C}” after the name of the folder so that the resultant string looks like “GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}”

c. Once you renamed the folder, the icon of the folder will change automatically and the name will be changed to GodMode.

PS: Note that any changes that you make on the God Mode will be made directly to the system so don’t make any major changes unless you are very sure about it.
You may rename it i.e. instead of GodMode any other name can be used.

GodMode contains list of all computer settings.


Below are the two screenshot of the settings. Apart from that there are many more settings you will find in GodMode (all categorized and accessible from one folder- GodMode)


More to come.. Stay tuned.. :)

Knowledge: Some good computer tricks

1. Finding Windows Product Key

Assuming you can boot your computer without any problems, you can easily create a simple VBscript that will read the value out of the registry and then translate it into the format that you need for reinstalling.

Copy and paste the following into a Notepad window:


Set WshShell = CreateObject("WScript.Shell")
MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
 
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(x + KeyOffset) = (Cur \ 24) And 255
Cur = Cur Mod 24
x = x -1
Loop While x >= 0
i = i -1
KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i -1
KeyOutput = "-" & KeyOutput
End If
Loop While i >= 0
ConvertToKey = KeyOutput
End Function

You’ll need to use File -> Save As, change the “Save as type” to “All Files” and then name it productkey.vbs or something similar ending with the vbs extension. We’d recommend saving to the desktop for easy access.


Once you’ve saved it, you can just double-click and the popup window will show you your product key.

Note :- If you use CTRL + C when the popup window is active, it will copy the contents of the window to the clipboard, and then you can paste it into Notepad or somewhere else.

2. Locate Your Android Phone Easily

It is very common situation when you can't find your phone. Then you start looking for it , searching in places like under the pillow , in some jeans pocket, bag etc, or may be that you left it in some place which definitely  you don't recall. Then you find some one who could make a call , but you realize that its on silent mod.


There are some apps available but what if you are just like me and a lot of us who don't have it installed. Here comes a Giant to save you all and search your android Phone in minutes. You don't need to find some other phone to ring your to find or to find the location of the phone if it is lost/stolen. The Giant named Google has it all figured out.

on Google just search  "find my phone" 
Baam!, There you go.
Google will now locate your phone.

  • You can now Ring you phone for 5 min in full volume even if it was in silent mod. It actually schedules a ring if the phone cannot be reached instantly.
  • You can in worst case erase your phone, helpful when phone gets stolen and sensitive data is there.
  • You can now be little more careless.
3. Create your own wifi hotspot on Windows 7 or 8 without using any external applications


You don't need "Connectify" or any other software for it. Also, you can save yourself from that 90 minutes counter in connectify. 

All you need to do is run the following two commands in cmd - 

Open cmd with Run as Administrator.

1) netsh wlan set hostednetwork mode=allow ssid=wifiname key=wifipassword
2) netsh wlan start hostednetwork

Best solution - Make a batch file of it and just run the file every time when you start the pc. 

To make a batch file -
First write the commands on a notepad


Then save it with the extension bat.  e.g. wifi.bat

Your batch file is made and now execute the file with Admin Privileges.

Important - For this to work, your sharing should be on in network properties for  the network/ethernet connection that you want to share through your  wifi:

Go to Open Network and Sharing Centre ->Change Adapter Settings(On left panel)\
Your wifi hotspot would be Microsoft Hosted Network Virtual Adaptor in the Network Connections.

Go to the properties of the LAN/ethernet/WiFi connection and make the changes accordingly.



Your wifi hotspot would be ready. :)

To stop the wifi hotspot - 
Write the following in command prompt (or create a batch file similar to above) : netsh wlan stop hostednetwork.

More coming soon.. :)

GSM: Difference between UMTS SIM (USIM) and GSM SIM

SIM and USIM
SIM cards (Subscriber Identity Module) are used to communicate on GSM networks and USIMs were introduced together with UMTS or 3G network.

Although it's possible to access 3G with a simple SIM card, the USIM have many advantages as compared to the SIM:

• A USIM is a tiny computer which is able to handle several mini internal applications, for instance a contact-less e-purse for the subway, a local service portal giving you access to your phone bill, etc, while SIM's analog is simple SIM menu which can't compute something by own other than communicating with carrier's server;
Bigger and Improved phone-book: USIM allows you to store thousands of contacts (limit on SIM is 255). Each contact can now contain email id and more than one phone number;

• A 3G (UMTS) handset equipped with a USIM card can be used to make video calls on 3g network;

• New and improved security algorithms are used to prevent unauthorized access to phone line, encrypt your calls and internet traffic and store contacts securely;

GSM: Why is the channel spacing in GSM 900 just 200KHz?

I've came across this question so many times in the period of telecommunication learning. Every time I asked the question, there was no one to properly answer the question, may be it was because I couldn't phrase the question in easily understandable way. Eventually I came across a few answers, here is the most convincing one from quora..

Why the channel spacing in GSM 900 is just 200KHz ?

It was a trade-off: wider channels = more bandwidth and more users.


Narrower channels are easier to implement (the equalizer) *

Other, very similar TDMA/FDD chose different channel sizes:
US D-AMPS / IS136 used 30KHZ (but only had three users instead of 8 or 16)
Japan's PDC used 25KHz, again for 3 users

GSM beat both of those. I don't know that proves 200KHz was "better"

There is no unique "right answer"

If you do an archive trawl through 3GPP standards from early 90s you'll probably find the analysis (I wish you luck...!)

* Remember these decisions were taken 20 years ago: the technology at the time is relevant, not what you can do now.

NOTE
It uses 25MHz each in 890-915 MHz and 935-960 MHz ranges with 200khz channel spacing 
That is not completely correct: GSM uses many more ranges than that e around 850 and 1800.

Programming: Reverse a stack using Recursion

You are not allowed to use loop constructs like while, for..etc, and you can only use the following ADT functions on Stack S:

1. isEmpty(S)
2. push(S)
3. pop()

Solution

The idea of the solution is to hold all values in Function Call Stack until the stack becomes empty. When the stack becomes empty, insert all held items one by one at the bottom of the stack.

1 -> top of the STACK
2
3
4 -> bottom of the STACK

First 4 is inserted at the bottom.
4

Then 3 is inserted at the bottom.
4 
3

Then 2 is inserted at the bottom.
4 
3
2

Then 1 is inserted at the bottom
4 
3
2
1 -> bottom of the STACK 


So we need a function that inserts at the bottom of a stack using the above given basic stack function.
//Below is a recursive function that inserts an element at the bottom of a stack.
void insertAtBottom(struct sNode** top_ref, int item)
{
   int temp; 
   if(isEmpty(*top_ref))
   { 
       push(top_ref, item);
   }
   else
   {     
     /* Hold all items in Function Call Stack until we reach end of
       the stack. When the stack becomes empty, the isEmpty(*top_ref)
       becomes true, the above if part is executed and the item is
       inserted at the bottom */
     temp = pop(top_ref);
     insertAtBottom(top_ref, item);

     /* Once the item is inserted at the bottom, push all the
          items held in Function Call Stack */
     push(top_ref, temp);
   }            
}

//Below is the function that reverses the given stack using insertAtBottom()
void reverse(struct sNode** top_ref)
{
  int temp;  
  if(!isEmpty(*top_ref))
  {

    /* Hold all items in Function Call Stack until we reach end of
     the stack */
    temp = pop(top_ref);                       
    reverse(top_ref);

    /* Insert all the items (held in Function Call Stack) one by one
       from the bottom to top. Every item is inserted at the bottom */
    insertAtBottom(top_ref, temp);
  }     
}

//Below is a complete running program for testing above functions.

#include
#include
#define bool int
/* structure of a stack node */
struct sNode
{
   char data;
   struct sNode *next;
};
/* Function Prototypes */
void push(struct sNode** top_ref, int new_data);
int pop(struct sNode** top_ref);
bool isEmpty(struct sNode* top);
void print(struct sNode* top);
/* Driveer program to test above functions */
int main()
{
  struct sNode *s = NULL;
  push(&s, 4);
  push(&s, 3);
  push(&s, 2);
  push(&s, 1); 
  printf("\n Original Stack ");
  print(s);
  reverse(&s);
  printf("\n Reversed Stack "); 
  print(s);
  getchar();
}   
/* Function to check if the stack is empty */
bool isEmpty(struct sNode* top)
{
  return (top == NULL)? 1 : 0;
}
/* Function to push an item to stack*/
void push(struct sNode** top_ref, int new_data)
{
  /* allocate node */
  struct sNode* new_node =
            (struct sNode*) malloc(sizeof(struct sNode));
  if(new_node == NULL)
  {
     printf("Stack overflow \n");
     getchar();
     exit(0);
  }         
  /* put in the data  */
  new_node->data  = new_data;
  /* link the old list off the new node */
  new_node->next = (*top_ref);
  /* move the head to point to the new node */
  (*top_ref)    = new_node;
}
/* Function to pop an item from stack*/
int pop(struct sNode** top_ref)
{
  char res;
  struct sNode *top;
  /*If stack is empty then error */
  if(*top_ref == NULL)
  {
     printf("Stack overflow \n");
     getchar();
     exit(0);
  }
  else
  {
     top = *top_ref;
     res = top->data;
     *top_ref = top->next;
     free(top);
     return res;
  }
}
/* Functrion to pront a linked list */
void print(struct sNode* top)
{
  printf("\n");
  while(top != NULL)
  {
    printf(" %d ", top->data);
    top =  top->next;
  }
}
Later...
+