Friday, October 31, 2014

Implementation Of Circular Queue in C++

Implementation Of Circular Queue in C++ Using Array 



#include<iostream.h>
#include<conio.h>
#define max 5
class queue{
private:
int front,rear;
int *queue;
public:
queue()
{   cout<<"\nThe size of Queue is Already = 5 or put 5 ";
     cin>>max;

  front=rear=-1;
}
void insert_rear(int n)
{
 if((front==0 && rear==max)||(front==(rear+1)))
 { cout<<"\nQueue is Full\n"; }
 else if(front==-1 && rear==-1)
    {  front=rear=0;
      queue[rear]=n;
    }
    else if ( rear==max && front>0)
    {  rear=0;
       queue[rear]=n;
    }
    else
    {  rear=rear+1;
       queue[rear]=n;
    }

}
void delete_front()
{
 if(front==-1 && rear==-1)
 { cout<<"\n Queue is Empty\n"; }
 else if(front==rear)
 {  front=rear=-1;  }
 else if(front==max)
 {  front=0;    }
 else
 {  front=front+1;
    cout<<"\nItem Deleted  = "<<queue[front-1];
 }
}
void display()
{
 int p;
 if(front==-1 && rear==-1)
 {  cout<<"\nQueue is Empty\n"; }
 else if(front<=max && rear<=front)
   {
 for(p=0;p<=rear;p++)  {
 cout<<queue[p]<<"   ";}
 for(p=front;p<=max;p++){
 cout<<queue[p]<<"   ";        }
 }
 else{
 for(p=front;p<=rear;p++)
 cout<<queue[p]<<"   ";         }
}
};
void main()
{
clrscr();
int a,b;
queue s;
while(getch()!=27)
{
cout<<"\n\t\t\"Select an Option\"\n\n\t||  1  |    Insert  ||\n\t||  2  |    Delete  ||\n\t||  3  |    Display ||";
cin>>a;
clrscr();
switch(a)
{
 case 1:{
cout<<"\nEnter value to be inserted:  ";
cin>>b;
s.insert_rear(b);    break;
}
 case 2:{
       s.delete_front();      break;
}
 case 3:{
       s.display();           break;
}
  }  //switch
   cout<<"\n\n\tAny key to Contenue || Esc to Exit\n";
 }  //while
}  //main



Here its the same code as in above but in this code i put some efforts to show how this circular queue works by shewing boxes and values in them . For batter understanding you must run this code. ☺


#include<iostream.h>
#include<conio.h>
class queue{
private:
int front,rear;
int *queue,max;
public:
queue()
{   cout<<"\nEnter the size of Queue =";
     cin>>max;

  front=rear=-1;
}
void insert_rear(int n)
{
 if((front==0 && rear==max)||(front==(rear+1)))
 { cout<<"\nQueue is Full\n"; }
 else if(front==-1 && rear==-1)
    {  front=rear=0;
      queue[rear]=n;
    }
    else if ( rear==max && front>0)
    {  rear=0;
       queue[rear]=n;
    }
    else
    {  rear=rear+1;
       queue[rear]=n;
    }

}
void delete_front()
{
 if(front==-1 && rear==-1)
 { cout<<"\n Queue is Empty\n"; }
 else if(front==rear)
 {  front=rear=-1;  }
 else if(front==max)
 {  front=0;    }
 else
 {  front=front+1;
    cout<<"\nItem Deleted  = "<<queue[front-1];
 }
}
void display()
{
 int p,z;
 for(int j=1;j<=max+1;j++){
gotoxy(j*5,11);cout<<"|````|";gotoxy(j*5,12);cout<<"|    |";
gotoxy(j*5,13);cout<<"``````";}
 if(front==-1 && rear==-1)
 {  cout<<"\nQueue is Empty\n"; }
 else if(front<=max && rear<=front)
   { z=5;
 for(p=0;p<=rear;p++,z+=5)  {
 gotoxy(z+1,12);cout<<queue[p];}
 z=(front+1)*5;for(p=front;p<=max;p++,z+=5){
 gotoxy(z+1,12);cout<<queue[p];        }
 }
 else{ z=(front+1)*5;
 for(p=front;p<=rear;p++,z+=5){
 gotoxy(z+1,12);cout<<queue[p];        } }
}
};
void main()
{
clrscr();
int a,b;
queue s;
while(getch()!=27)
{
cout<<"\n\t\t\"Select an Option\"\n\n\t||  1  |    Insert  ||\n\t||  2  |    Delete  ||\n\t||  3  |    Display ||";
cin>>a;
clrscr();
switch(a)
{
 case 1:{
cout<<"\nEnter value to be inserted:  ";
cin>>b;
s.insert_rear(b); s.display();   break;
}
 case 2:{
       s.delete_front();  s.display();    break;
}
 case 3:{
       s.display();       s.display();    break;
}
  }  //switch
   cout<<"\n\n\tAny key to Contenue || Esc to Exit\n";
 }  //while
}  //main


Top Android Applications For FREE CALLS Without Internet


Android FREE CALL Applications 2014

Android FREE CALL Applications

Android No doubt the most popular operating system in the world with hundred of thousand interactive useful applications and tools. In this article we are going to show you some useful applications to make FREE CALLS Without using VOIP i.e direct Mobile to Mobile calls using applications.

  • CFC Application

This is a sponsored service and you need to earn few points by completing short surveys in order to get points required to make unlimited Free Calls and send unlimited texts.

  • Dingaling

Dingaling supports peer-to-peer voice calls over 3G / 4G and its totally FREE. You just need to install the application to make calls.

  • Free Kall 

Free Call is an innovative method of calling and it doesn't require any application. You just need to dial an toll Free number [ Can be found here www.freekall.in ] and provide your destination number on receiving call back .

Its an Ad supported service and you might listen few short Ads in between while your call is going on.

  • Libon

Call more than 90+ countries with Libon totally FREE. Apart from FREE CALLS Libon also supports Instant Messages, Chat etc.

  • Voxox


Make 60 Minutes of FREE Calling with VOX supporting over 90+ countries. 

Thursday, October 30, 2014

Just For Fun

Must Select > Copy > Paste > Compile >Run and Enjoy :) ☺ 

#include<iostream.h>
#include<conio.h>
#include<dos.h>
void main()
{int i;
for(i=10;i<51;i++)
{clrscr();gotoxy(20,5);
textcolor(i);
cout<<"|| P R O G R A M M I N G      S E E K E R Z  ||";
gotoxy(30,30);cout<<"pcphunt.blogspot.com";
gotoxy(i,15);
cout<<"\2";
gotoxy(i,16);
cout<<"()";
gotoxy(i,17);
cout<<"_/|_ ";
delay(190);
clrscr();
gotoxy(20,5);
cout<<"||  P R O G R A M M I N G    S E E K E R Z  ||";
gotoxy(30,30);
cout<<"pcphunt.blogspot.com";
gotoxy(i,15);
cout<<" \1";
gotoxy(i,16);
cout<<" ))";
gotoxy(i,17);
cout<<"_|\\_ ";
delay(190);
}gotoxy(35,16);
cout<<"Let's ROcK!!";
gotoxy(30,25);
cout<<"Keep Coding ..Be Seekerz \2 :)\n\n\t\t\t`~~ Hafiz Usman ~~";
getch();
}

Wednesday, October 29, 2014

Decimal to Binary Conversion using Stack in C++

#include<iostream.h>
#include<conio.h>
class stack{
private:
int top,max;
int *stackarr;
public:
stack()
{
cout<<"\nEnter the size of stack: ";
cin>>max;
top=-1;
}
void push(int n)
{
if(top==max)
cout<<"\nStack is full\n";
else
top=top+1;
stackarr[top]=n;
}
int pop()
{
if(top==-1)
cout<<"\nStack is empty\n";
else
top=top-1;
return stackarr[top+1];
}
void decimal(int num)
{
cout<<"\n\nThe decimal to binery convertion of "<<num<<" is Below.\n ";
   for(num;num>0;num=num/2)
  {  push(num%2);       }
while(top!=-1)
  { cout<<pop()<<" ";   }
}
};
void main()
{
clrscr();
int value=0;
stack obj;
cout<<"\nEnter a number in Decimal notaion : ";
cin>>value;
obj.decimal(value);
getch();
}

Tuesday, October 28, 2014

Implementation of Stacks

"Implementation of Stacks in Array through classes in C++"


#include<iostream.h>
#include<conio.h>
class stack{
private:
int top,max;
int *stackarr;
public:
stack()
{
cout<<"\nEnter the size of stack: ";
cin>>max;
top=-1;
int *stackarr=new int[max];
}
void push(int n)
{
if(top==max)
cout<<"\nStack id full\n";
else
top=top+1;
stackarr[top]=n;
}
void pop()
{
if(top==-1)
cout<<"\nStack is empty\n";
else
cout<<"\nThe stack element "<<stackarr[top]<<" is poped\n";
top=top-1;
}
void display()
{

for(int i=0;i<=top;i++)
cout<<"\nvalue is :"<<stackarr[i];
}
};
void main()
{
clrscr();
int a=0,value=0;
stack obj;
while(getch()!=27)
{
cout<<"\n \n\n\t\tSelect an option:\n 1   for Push\n 2   for Pop\n 3   for Display ";
cin>>a;
clrscr();
switch(a)
{
case 1:
{
cout<<"\nEnter value for index: ";
cin>>value;
obj.push(value);
break;
}
case 2:
obj.pop();
break;
case 3:
obj.display();
break;
}
cout<<"\n\n\t   || Press Esc Key to exit || Any Key For next Operation  ||";
}
}

Saturday, October 25, 2014

Double Link-List in C++

#include<iostream.h>
#include<conio.h>
class node
{
public:
int value,size;
node *nextnode,*headnode,*prenode;
node *lastnode,*currentnode;
public:
node();
void add(int);
int get()
{
return value;
}
void set(int value)
{
this->value=value;
}
void setnext(node *nextnode)
{
this->nextnode=nextnode;
}
node *getnext()
{ return nextnode;}
void setprev(node* prenode)
{this->prenode=prenode;}
node *getprev()
{ return prenode;}
void  display()
{ cout<<"Adress of headnode      "<<headnode<<"       Headnode hold: "<<headnode->getnext()<<endl;
for(node *a=headnode->getnext();a->getnext()!=NULL;a=a->getnext())
{

cout<<"\nAddress of  node:       "<<a;
cout<<"\nAdress of next node:    "<<a->getnext()<<"    Adress of Preves node: "<<a->getprev()<<endl;
cout<<"value of node:  "<<a->value<<endl;

}
}
};
node::node()
{
headnode=new node();
headnode->setnext(NULL);
currentnode=NULL;
size=0;
}
void node::add(int n)
{
node *newnode=new node();
newnode->set(n);
if(currentnode!=NULL)
{
nextnode->setnext(currentnode->getnext());
newnode->setprev(currentnode);
currentnode->setnext(newnode);
lastnode=currentnode;
currentnode=newnode;
}
else
{
newnode->setnext(NULL);
newnode->setprev(headnode);
headnode->setnext(newnode);
lastnode=headnode;
currentnode=newnode;

}
size++;
}
void main()
{
clrscr();
node obj,bol;

obj.add(10);
obj.add(20);
obj.add(30);
obj.add(40);
obj.add(50);

obj.display();

getch();
}


Deletion of Any node in Circular link-List

#include<iostream.h>
#include<conio.h>
class node{
private:
int value,size;
node *last,*first,*nextnode;
public:
node()                     //constructor
{value=size=0; last=first=nextnode=NULL;}
int get()
{ return value;  }
void set(int value)
{ this->value=value; }
node *getnext()
{ return nextnode; }
void setnext(node *nextnode)
{ this->nextnode=nextnode; }
void add(int n)
{
 node *newnode=new node();
 newnode->set(n);
 if(first==NULL && last==NULL)
 {
  newnode->setnext(NULL);
  first=newnode;
  last=newnode;
 }
  else
 {
 last->setnext(newnode);
 newnode->setnext(first);
 last=newnode;
 }
 size++;
}
void display()
{
cout<<"\nAdress of first node: "<<first<<"  Adress first node holding: "<<first->getnext()<<endl;
cout<<"Value of First node:    "<<first->get()<<endl;
for(node *a=first->getnext();a->getnext()!=first->getnext();a=a->getnext())
 {
 cout<<"\nAdres of node:  "<<a<<"    Adress that hold: "<<a->getnext()<<endl;
 cout<<"Value of node:  "<<a->get()<<endl;
 }
}
///// find functions :)
node *find(int n)
{
for(node *a=first->getnext();a!=first;a=a->getnext())
 {
 if(a->get()==n)
 return a;
 }
}
node *find1(node *n)
{
for(node *a=first->getnext();a->getnext()!=n->getnext();a=a->getnext())
 {
 if(a->getnext()==n)
 return a;
 }
}
///// Remove Function
void remove(int n)
{
node *p1=NULL;
 if(first==NULL && last==NULL)
 {  cout<<" \n List is Empty "; return;}
 else if(first==last && n==first->get())
 {  delete first,last; first=last=NULL; cout<<"\nvalues delete";return; }
else
 {
  node *p=find(n);

  if(p==first)
   { p1=last;
    p1->setnext(first->getnext());
    first=first->getnext();
    delete p;
   }
  else if(p==last)
     { p1=find1(p);
       p1->setnext(p->getnext());
       last=p1;
       delete p;
     }
   else
   {
     p1=find1(p);
     p1->setnext(p->getnext());
      delete p;
   }
 }
}
};
 void main()
 {
 clrscr();
 int v=0;
 node obj;
 obj.add(11);
 obj.add(12);
 obj.add(13);
 obj.add(14);
 obj.add(15);
 obj.add(16);
obj.display();
while(getch()==13)
 {
 cout<<"\n\nEnter the value of node you want to delete: ";
 cin>>v;
 clrscr();
 obj.remove(v);
 obj.display();
 cout<<"\n\n\n\n\t Delete other  ::Enter    ||   Exit::Any Key ";

 }
}

Friday, October 24, 2014

Circular Link-List in C++

#include<iostream.h>
#include<conio.h>
class node{
private:
int value,size;
node *last,*first,*nextnode;
public:
node()                     //constructor
{ last=first=NULL; }
int get()
{ return value;  }
void set(int value)
{ this->value=value; }
node *getnext()
{ return nextnode; }
void setnext(node *nextnode)
{ this->nextnode=nextnode; }
void add(int n)
{
 node *newnode=new node();
 newnode->set(n);
 if(first==NULL && last==NULL)
 {
  newnode->setnext(NULL);
  first=newnode;
  last=newnode;
 }
  else
 {
 last->setnext(newnode);
 newnode->setnext(first);
 last=newnode;
 }
 size++;
}
void display()
{
cout<<"Adress of first node: "<<first<<"  Adress first node holding: "<<first->getnext()<<endl;
for(node *a=first->getnext();a->getnext()!=first->getnext();a=a->getnext()){
cout<<"Adres of node: "<<a<<"    Adress that hold: "<<a->getnext()<<endl;
cout<<"Value of node: "<<a->get()<<endl<<endl;
}
}
};
 void main()
 {
 clrscr();
 node obj;
 obj.add(22);
 obj.add(33);
 obj.add(44);
 obj.add(55);
obj.display();
getch();
  }

Sunday, October 19, 2014

Concatenate or Merge two Linklists in C++

#include<iostream.h>
#include<conio.h>
class node
{
public:
int value,size;
node *nextnode,*headnode;
node *lastnode,*currentnode;
public:
node();
void add(int);
int get()
{
return value;
}
void set(int value)
{
this->value=value;
}
void setnext(node *nextnode)
{
this->nextnode=nextnode;
}
node *getnext()
{
return nextnode;
}

void  display()
{ cout<<"headnode hold: "<<headnode->getnext()<<endl;
for(node *a=headnode->getnext();a->getnext()!=NULL;a=a->getnext())
{

cout<<"Adress of  node:  "<<a<<"      Adress holdin /next node:  "<<a->getnext()<<endl;
cout<<"value of node:  "<<a->value<<endl<<endl;

}
}
friend void  conc( node c,node b)
{
c.currentnode->setnext(b.headnode->getnext());
delete b.headnode;
}
};
node::node()
{
headnode=new node();
headnode->setnext(NULL);
currentnode=NULL;
size=0;
}
void node::add(int n)
{
node *newnode=new node();
newnode->set(n);
if(currentnode!=NULL)
{
nextnode->setnext(currentnode->getnext());
currentnode->setnext(newnode);
lastnode=currentnode;
currentnode=newnode;
}
else
{
newnode->setnext(NULL);
headnode->setnext(newnode);
lastnode=headnode;
currentnode=newnode;

}
size++;
}
void main()
{
clrscr();
node obj,bol;
obj.add(11);
obj.add(20);
obj.add(30);
obj.add(40);
obj.display();
cout<<"Press any key to see 2nd link list: ";
getch();
clrscr();
cout<<endl<<"XXXXXXXXXXXXXXXXX"<<endl;
bol.add(25);
bol.add(23);
bol.add(22);
bol.display();
cout<<"Press any key to see 1st link list after concatination or merging ";
getch();
clrscr();
conc(obj,bol);
obj.display();
getch();
}

Sunday, October 12, 2014

Insertion at any point in LINK-LIST

#include<iostream.h>
#include<conio.h>
class node
{
private:
int value,size;
node *nextnode,*headnode;
node *lastnode,*currentnode;
public:
node();
void add(int);
int get()
{
return value;
}
void set(int value)
{
this->value=value;
}
void setnext(node *nextnode)
{
this->nextnode=nextnode;
}
node *getnext()
{
return nextnode;
}
void inline display()
{
for(node *a=headnode->getnext();a->getnext()!=NULL;a=a->getnext())
{

cout<<"address of  node  "<<a<<"       "<<a->getnext()<<endl;
cout<<a->value<<endl;

}
}
void find(int z)
{
int x;
cout<<endl<<"enter value";
cin>>x;
for(node *a=headnode->getnext();a->getnext()!=NULL;a=a->getnext())
if(a->get()==z)
currentnode=a;
node *newnode=new node();
newnode->set(x);
newnode->setnext(currentnode->getnext());
currentnode->setnext(newnode);
   }
};
node::node()
{
headnode=new node();
headnode->setnext(NULL);
currentnode=NULL;
size=0;
}
void node::add(int n)
{
node *newnode=new node();
newnode->set(n);
if(currentnode!=NULL)
{
nextnode->setnext(currentnode->getnext());
currentnode->setnext(newnode);
lastnode=currentnode;
currentnode=newnode;
}
else
{
newnode->setnext(NULL);
headnode->setnext(newnode);
lastnode=headnode;
currentnode=newnode;

}
size++;
}
void main()
{
clrscr();
int q;
node obj;
obj.add(10);
obj.add(20);
obj.add(30);

obj.add(40);
obj.display();
cout<<endl<<"Enetr a value for search: ";
cin>>q;
obj.find(q);
obj.display();
getch();
}

Tuesday, October 7, 2014

How to create a single linklist in C++

#include<iostream.h>
#include<conio.h>
class node{
private:
int value,size;
node *newnode,*currentnode,*prevnode,*headnode,*lastnode,*nextnode;
public:
node();
void add(int);
int get()
{
 return value;
}
void set(int value)
{
this->value=value;
}
node *getnext()
{
return nextnode;
}
void setnext(node *nextnode)
{
this->nextnode=nextnode;
}
node *getprev()
{
return prevnode;
}
void setprev(node *prevnode)
{
this->prevnode=prevnode;
}
};
node::node()
{
headnode=new node();
headnode->setnext(NULL);
currentnode=NULL;
size=0;
}
void node::add(int n)
{
node *newnode=new node();
newnode->set(n);
if(currentnode!=NULL)
{
newnode->setnext(currentnode->getnext());
currentnode->setnext(newnode);
lastnode=currentnode;
currentnode=newnode;
}
else
{
newnode->setnext(NULL);
headnode->setnext(newnode);
lastnode=headnode;
currentnode=newnode;
}size++;
}

void main()
{
node obj;
obj.add(10);
obj.add(20);
getch();
}