Tuesday, January 19, 2010

KNAPSACK

#include
#include

void Gknapsack(int [],int,int);

void main()
{
clrscr();
int i,w[30],p[30],m,n;
/* w array for weights.
p array for profits.
m stands for maximum capacity.
n stands for number od items.
i is counter.*/
cout<<"enter the number of items::";
cin>>n;
cout< cin>>m;
cout< for(i=1;i<=n;i++)
cin>>w[i];
cout< for(i=1;i<=n;i++)
cin>>p[i];
Gknapsack(w,m,n);
getch();
}

void Gknapsack(int w[],int m,int n)
{
float x[30];
int U=m;
for(int i=1;i<=n;i++)
x[i]=0;
for(i=1;i<=n;i++)
{
if(w[i]>U)
break;
x[i]=1;
U=U-w[i];
}
if(i<=n)
x[i]=(float)U/w[i];
cout< for(i=1;i<=n;i++)
cout<}

HEAPSORT

#include
#include
#include

void heapsort(int [],int);
void heapify(int [],int);
void adjust(int[],int,int);

void main()
{
clrscr();
int a[50],x,i;
cout<<"Enter the size of the array::";
cin>>x;
cout< for(i=1;i<=x;i++)
cin>>a[i];
heapsort(a,x);
cout< for(i=1;i<=x;i++)
cout< getch();
}

void heapsort(int a[],int n)
{
heapify(a,n);
for(int i=n;i>=2;i--)
{
int temp;
temp=a[i];
a[i]=a[1];
a[1]=temp;
adjust(a,1,i-1);
}
}

void heapify(int a[],int n)
{
for(int i=floor(n/2);i>=1;i--)
adjust(a,i,n);
}

void adjust(int a[],int i,int n)
{
int j=2*i;
int item=a[i];
while(j<=n)
{
if((j j=j+1;
if(item>=a[j])
break;
a[j/2]=a[j];
j=2*j;
}
a[j/2]=item;
}

DEPTH FIRST SEARCH

#include
#include
#include
#include
#include

struct node
{
int data,status;
node *lftchild,*rtchild;
}*root,*temp,*t,*save,*xyz,*item;

struct stack
{
node *info;
stack *link;
}*top,*temp1;

void push(node *);
node *pop();

void main()
{
clrscr();
root=0;
int ch=0;
char c;
while(ch==0)
{
cout< cout< cout< cout< cin>>ch;
switch(ch)
{
case 1:
{
int item;
int found;
do
{
temp=(node *)malloc(sizeof (node));
cout< cin>>item;
temp->status=0;
temp->data=item;
found=0; //found is false
save=0;
t=root;
while(t!=0 && found==0)
{
save=t;
if(item==t->data)
found=1;
else
{
if(itemdata)
t=t->lftchild;
else
t=t->rtchild;
}
}
if(found==1) //found is true
cout<<"item is already in the tree"< else
{
if(save==0)
{
root=temp;
root->lftchild=0;
root->rtchild=0;
}
else
{
if(itemdata)
save->lftchild=temp;
else
save->rtchild=temp;
}
}
cout<<"do you want to insert again(y/n)::";
cin>>c;
}while(c=='y' || c=='Y');
if(c=='n' || c=='N')
{
ch=0;
break;
}
}

case 2:
{
top=0;
if(root==0)
{
cout< ch=0;
break;
}
push(root);
while(top!=0)
{
xyz=pop();
xyz->status=2;
cout<data<<"\t";
if(xyz->rtchild->status==0)
push(xyz->rtchild);
if(xyz->lftchild->status==0)
push(xyz->lftchild);
}
ch=0;
break;
}

case 3:
{
ch=5;
exit(0);
}
}
}
getch();
}

void push(node *p)
{
temp1=(stack *)malloc(sizeof(stack));
p->status=1;
temp1->info=p;
temp1->link=top;
top=temp1;
}

node *pop()
{
item=top->info;
top=top->link;
return(item);
}

BINARY TREE

#include
#include
#include
#include
#include

struct node
{
int data;
node *lftchild,*rtchild;
}*root,*temp,*t,*save;

void search(node *,int);
void print(node *);

void main()
{
clrscr();
root=0;
int ch=0;
char c;
while(ch==0)
{
cout< cout< cout< cout< cout< cin>>ch;
switch(ch)
{
case 1:
{
int item;
int found;
do
{
temp=(node *)malloc(sizeof (node));
cout< cin>>item;
temp->data=item;
found=0; //found is false
save=0;
t=root;
while(t!=0 && found==0)
{
save=t;
if(item==t->data)
found=1;
else
{
if(itemdata)
t=t->lftchild;
else
t=t->rtchild;
}
}
if(found==1) //found is true
cout<<"item is already in the tree"< else
{
if(save==0)
{
root=temp;
root->lftchild=0;
root->rtchild=0;
}
else
{
if(itemdata)
save->lftchild=temp;
else
save->rtchild=temp;
}
}
cout<<"do you want to insert again(y/n)::";
cin>>c;
}while(c=='y' || c=='Y');
if(c=='n' || c=='N')
{
ch=0;
break;
}
}

case 2:
{
int element;
cout< cin>>element;
do
{
search(root,element);
cout< cin>>c;
}while(c=='y' || c=='Y');
if(c=='n' || c=='N')
{
ch=0;
break;
}
}

case 3:
{
if(root==0)
{
cout<<"there is no element in the tree"< ch=0;
break;
}
else
{
t=root;
print(t);
}
ch=0;
break;
}

case 4:
{
ch=4;
exit(0);
}
}
}
getch();
}

void print(node *t)
{
if(t!=0)
{
print(t->lftchild);
cout<data;
print(t->rtchild);
}
}

void search(node *t,int element)
{
if(t==0)
cout<<"there is no element in the tree"< else
{
if(t->data==element)
cout<<"item found"< else
{
if(elementdata)
search(t->lftchild,element);
else
search(t->rtchild,element);
}
}
}

Thursday, January 14, 2010

BREADTH FIRST SEARCH

#include
#include
#include
#include
#include

struct node
{
int data,status;
node *lftchild,*rtchild;
}*root,*temp,*t,*save,*xyz,*item;

struct queue
{
node *info;
queue *linkback,*linkforward;
}*front,*rear,*temp1;

void insert(node *);
node* remove();

void main()
{
clrscr();
front=0;
rear=0;
root=0;
int ch=0;
char c;
while(ch==0)
{
cout<<<"1:insert into binary search tree"; cout<<<"2:print the elements of the tree"; cout<<<"3:exit"; cout<<<"enter your choice"; cin>>ch;
switch(ch)
{
case 1:
{
int item;
int found;
do
{
temp=(node *)malloc(sizeof (node));
cout<<<"enter the element to be inserted::"; cin>>item;
temp->status=0;
temp->data=item;
found=0; //found is false
save=0;
t=root;
while(t!=0 && found==0)
{
save=t;
if(item==t->data)
found=1;
else
{
if(itemdata)
t=t->lftchild;
else
t=t->rtchild;
}
}
if(found==1) //found is true
cout<<"item is already in the tree"<lftchild=0;
root->rtchild=0;
}
else
{
if(itemdata)
save->lftchild=temp;
else
save->rtchild=temp;
}
}
cout<<"do you want to insert again(y/n)::"; cin>>c;
}while(c=='y' || c=='Y');
if(c=='n' || c=='N')
{
ch=0;
break;
}
}

case 2:
{
// front=0;
if(root==0)
{
cout<<<"tree is empty"<status=2;
cout<data<<"\t"; if(xyz->lftchild->status==0)
insert(xyz->lftchild);
if(xyz->rtchild->status==0)
insert(xyz->rtchild);
}
ch=0;
break;
}

case 3:
{
ch=5;
exit(0);
}
}
}
getch();
}

void insert(node *p)
{
if(front==0 && rear==0)
{
temp1=(queue *)malloc(sizeof(queue));
p->status=1;
temp1->info=p;
temp1->linkback=0;
temp1->linkforward=0;
front=temp1;
rear=temp1;
}
else
{
temp1=(queue *)malloc(sizeof(queue));
p->status=1;
temp1->info=p;
rear->linkforward=temp1;
temp1->linkback=rear;
rear=temp1;
temp1->linkforward=0;
}
}

node *remove()
{
item=front->info;
front=front->linkforward;
return(item);
}

Saturday, December 26, 2009

Earn Money Online Thru Reliable Source

http://www.clixsense.com/?3032230


http://mGinger.com/index.jsp?inviteId=288972


http://viewbestads.com/ref/NzU2NDc=aXY=

Tuesday, November 24, 2009

Full Forms

Meaning of family...... ....


Here Is The Answer ........... FAMILY =

(F)ather
(A)nd
(M)other
(I)
(L)ove
(Y)ou


WHY does a man want to have a WIFE?

Because:

(W)ashing
(I)roning
(F)ood
(E)ntertainment


WHY does a woman want to have a HUSBAND?

Because:

(H)ousing
(U)nderstanding
(S)haring
(B)uying
(A)nd
(N)ever
(D)emanding


Do you know that a simple "HELLO" can be a sweet one?

Especially from your love one. (I mean not only from the boyfriend/girlfrien d).

The word HELLO means :

(H)ow are you?
(E)verything all right?
(L)ike to hear from you
(L)ove to see you soon!
(O)bviously, I miss you..