Wednesday, 26 October 2011

Industrial Tour Letter


http://www.mediafire.com/?cft0sdcxytuf3lc



Download Industrial Letter  And Submit it To Mahesh or Pranathi

Monday, 24 October 2011

Program on Hashing Chain



#include<iostream>
#include<cstdlib>
using namespace std;
class hashch
{
      struct node
      {
             int value;
             node *link;
      };
     public:
            struct node *hashtable[10];
            void insert(int);
            void del(int);
            bool search(int);
            void display();
            void inp();

};
void hashch::inp()
{
 for(int i=0;i<10;i++)
     {
                      hashtable[i]=NULL;
     }
}
void hashch::insert(int val)
{
     int c,i;

     node *t;
     t=new node;
     t->value=val;
     t->link=NULL;
     c=val%10;
     if(hashtable[c]==NULL)
           hashtable[c]=t;
     else
     {
         node*p;
         p=new node;
         p=hashtable[c];
         if(val<p->value)
         {
                       t->link=p;
                       hashtable[c]=t;
         }
         else
         {
             while (val>p->link->value&&p->link!=NULL)
             p=p->link;
             if(p->link->link!=NULL)
            {
                t->link=p->link;
                p->link=t;
             }
             else if(val<p->link->value)
             {
                  t->link=p->link;
                  p->link=t;
             }
             else
             p->link->link=t;
         }
     }
}
void hashch::del(int val)
{
     int c;
     node *t,*p ;
     c=val%10;
     t=new node;
     p=new node;

     if(hashtable[c]!=NULL)
     {
                          if(t->value==val)
                          {
                            t=hashtable[c];
                            hashtable[c]=hashtable[c]->link;
                           delete t;
                          }
                          else
                          {
                                  p=hashtable[c];
                                  while(p->link->link!=NULL&&p->link->value!=val)
                                  {
                                       p=p->link;

                                  }
                                  if(t->link->link!=NULL)
                                  {
                                                          t=p->link;
                                                          p->link=p->link->link;
                                                          free(t);
                                  }
                                   else
                                   t->link=NULL;
                          }
}
                          else
                          cout<<"\nThe bucket doesnt exist\n";
}

bool hashch::search(int val)
{
     int c;
     node *t;
     c=val%10;
     t=hashtable[c];
     if(hashtable[c]!=NULL)
     {
                           while(t!=NULL)
                           {
                                         if(t->value==val)
                                         {
                                                          cout<<"Found\n";
                                                          return true;
                                         }
                                         else
                                         {
                                             t=t->link;
                                         }
                           }


                               cout<<"The value doesnt exist\n";
                                return false;

     }
     else
     cout<<"The bucket is empty\n";
}
void hashch::display()
{
    node *p[10];
   node *t;

     int i;
    for(i=0;i<10;i++)
{
     p[i]=hashtable[i];
}
    for(i=0;i<10;i++)
    {
             t=new node;
                     if(p[i]!=NULL)
                     {
                                   t=p[i];
                                    while(t!=NULL)
                                   {

                                   cout<<t->value<<"\t";
                                    t=t->link;
                                    }
                     cout<<"\n";
                     }
                     else
                     cout<<"NULL\n";
      }
}
int main()
{
    hashch ch;
    int option;
    int ele;

    bool ans;
    ch.inp();
    while(1)
    {
            cout<<"\nEnter your choice\n";
            cout<<"\n1.Insert\n2.Delete\n3.Search\n4.Display\n5.Exit\n";
            cin>>option;
            switch(option)
            {
                          case 1:cout<<"\nEnter what you want to insert\n";
                          cin>>ele;
                          ch.insert(ele);
                               break;
                          case 2:cout<<"\nEnter what you want to delete\n";
                               cin>>ele;
                               ch.del(ele);
                                break;
                          case 3:cout<<"\nEnter what you want to search\n";
                                 cin>>ele;
                                 ans=ch.search(ele);
                                 if(ans)
                                  cout<<"\nFound\n";
                                 else
                                  cout<<"\nMissing\n";
                                 break;
                          case 4: ch.display();
                                  break ;
                          case 5: exit(1);
            }
    }
    return 0;

}




OUTPUT:-

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
1

Enter what you want to insert
2

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
3

Enter what you want to search
2
Found

Found

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
1

Enter what you want to insert
4

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
4
NULL
NULL
2
NULL
4
NULL
NULL
NULL
NULL
NULL

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
1

Enter what you want to insert
6

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
4
NULL
NULL
2
NULL
4
NULL
6
NULL
NULL
NULL

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit

Program on add and multiplication of Polynomials


#include<iostream>
using namespace std;
#define n 100
class poly
{
 private:
                int a[n], b[n], add[n], mul[n], p, q, at;
        public:
                void init ( );
void input ( );
                void process ( );
                void display ( );
};
void poly :: init ( )
{
        int i;
        for( i = 0; i < n; i++)
                a[ i ] = b [ i ] = add[ i ] = mul[ i ] = 0;
}
void poly :: input ( )
{
        int i;
    cout<<"\nEnter Degree Of First Polynomial::";
        cin>>p;
        cout<<"\nEnter Degree Of Second Polynomial::";
        cin>>q;
        cout<<"\nEnter Values in First Polynomial\n";
        for( i = 0; i <= p; i++)
        {
                cout<<"\nEnter X^"<<i<<" The Coefficient";
                cin>>a[ i ];
        }
        cout<<"\nEnter Values in Second Polynomial\n";
        for( i = 0; i <= q; i++)
        {
                cout<<"\nEnter X^"<<i<<" The Coefficient";
                cin>>b[ i ];
        }
}
void poly :: process ( )
{
        int i, j;
        if( p > q )
                at = p;
        else
                at = q;
        for ( i = 0; i <= at;i++   )
                add[ i ] = a[ i ] + b[ i ];
                for( i = 0;  i <= p;  i++)
                        for( j = 0; j <= q; j++)
                                  mul[i+j]+= a[i]*b[j];
}
void poly :: display ( )
{
 int i;
cout<<"Addition Of Two Polynomial Expressions Are\n\n";
for( i = at; i >=0 ; i--)
cout<<add[i]<<"X^"<<i<<"+";
cout<<"\n\nMultiplication Of Two Polynomial Expressions Are\n\n";
for( i = p + q; i >= 0; i--)
cout<<mul[i]<<"X^"<< i <<"+";
}
int main()
{
poly ob;
ob.init ( );
ob.input ( );
ob.process ( );
ob.display ( );
return 0;
}


OUTPUT:-

Enter Degree Of First Polynomial::2

Enter Degree Of Second Polynomial::2

Enter Values in First Polynomial

Enter X^0 The Coefficient1

Enter X^1 The Coefficient2

Enter X^2 The Coefficient5

Enter Values in Second Polynomial

Enter X^0 The Coefficient6

Enter X^1 The Coefficient4

Enter X^2 The Coefficient7
Addition Of Two Polynomial Expressions Are

12X^2+6X^1+7X^0+

Multiplication Of Two Polynomial Expressions Are

35X^4+34X^3+45X^2+16X^1+6X^0+

Program on Graph Traversal


#include<iostream>
using namespace std;
class graphtraversal
{
        public:
                int size;
                int **adj;
                void readadj();
                void dfs();
                void bfs();
};
void graphtraversal::readadj()
{
        cout<<"enter no of vertices\n";
        cin>>size;
        adj=new int *[size];
        for(int i=0;i<size;i++)
                adj[i]=new int [size];
        cout<<"enter adj matrix:\n";
        for(int i=0;i<size;i++)
                for(int j=0;j<size;j++)
                        cin>>adj[i][j];
}
void graphtraversal::dfs()
{
        int stack[size],top=-1;
        int start,visited[size];
        for(int i=0;i<size;i++)
                visited[i]=0;
        cout<<"enter starting node:\n";
        cin>>start;
        stack[++top]=start;
        visited[start]=1;
        while(top!=-1)
        {
                start=stack[top--];
                cout<<start<<"  ";
                for(int i=0;i<size;i++)
                {
                        if(adj[start][i]==1 && visited[i]!=1)
                        {
                                stack[++top]=i;
                                visited[i]=1;
                        }
                }
        }
}
void graphtraversal::bfs()
{
        int queue[size],f=-1,r=0;
        int strt,visited[size];
        for(int i=0;i<size;i++)
                visited[i]=0;
        cout<<"enter starting node\n";
        cin>>strt;
        queue[r++]=strt;
        visited[strt]=1;
        while(f!=r-1)
        {
                strt=queue[++f];
                cout<<strt<<" ";
                for(int i=0;i<size;i++)
                {
                        if(adj[strt][i]==1 && visited[i]!=1)
                        {
                                queue[r++]=i;
                                visited[i]=1;
                        }
                }
        }
}
int main()
{
        graphtraversal ob;
        int op,n=1;
        while(n==1)
        {
                cout<<"\nenter the option\n";
                cout<<"1.read adj\n2.DFS\n3.BFS\n4.exit\n";
                cin>>op;
                switch(op)
                {
                        case 1:
                                ob.readadj();
                                break;
                        case 2:
                                ob.dfs();
                                break;
                        case 3:
                                ob.bfs();
                                break;
                        case 4:
                                n=0;
                                break;
                }
        }
}


OUTPUT:-

enter the option
1.read adj
2.DFS
3.BFS
4.exit
1
enter no of vertices
4
enter adj matrix:
0
^Z
[4]+  Stopped                 ./a.out
[b520@localhost ~]$ ./a.out

enter the option
1.read adj
2.DFS
3.BFS
4.exit
1
enter no of vertices
4
enter adj matrix:
0 0 1 0
1 0 0 0
0 0 0 1
0 1 0 0

enter the option
1.read adj
2.DFS
3.BFS
4.exit
2
enter starting node:
0
0  2  3  1
enter the option
1.read adj
2.DFS
3.BFS
4.exit
3
enter starting node
0
0 2 3 1
enter the option
1.read adj
2.DFS
3.BFS
4.exit
4



Program on Hashing


#include<iostream>
#include<cstdlib>
using namespace std;
class ihash
{
      int *p;
      int d;
      public:
             ihash()
             {
                    d=10;
                    }
                    void insert(int);
                    bool search(int);
                    void del(int);
                    void display();
                    void inp();
};
void ihash::inp()
{
     p=new int[10];
     for(int i=0;i<10;i++)
       p[i]=-1;
}

void ihash::insert(int key)
{

     int i;
     i=key%d;
     if(p[i]==-1)
       p[i]=key;
       else
       {
           int j=i;
            i=(i+1)%d;
            while(i!=j)
            {
                       if(p[i]==-1)
                       {
                           p[i]=key;
                           break;
                           }
                        else
                        i=(i+1)%d;
            }
}
}
bool ihash::search(int key)
{
     int i,j;
     i=key%d;
     if(p[i]==key)
       return true;
     else
     {
         j=i;
         i=(i+1)%d;
         while(i!=j)
         {
                    if(p[i]==key)
                    return key;
                    else
                    i=(i+1)%d;
         }
         return false;
     }
}
void ihash::del(int key)
{
     int i,j;
     i=key%d;
     if(p[i]==key)
       p[i]=-1;
     else
     {
         j=i;
         i=(i+1)%d;
         while(i!=j)
         {
                    if(p[i]==key)
                      p[i]=-1;
                    else
                     i=(i+1)%d;
         }
     }

}
void ihash::display()
{
     for(int i=0;i<10;i++)
     {
             if(p[i]==-1)
             cout<<"NULL\n";
             else
             cout<<p[i]<<"\n";
             }
             }
int main()
{
    int option;
    bool ans;
    int key;
    ihash ih;
      ih.inp();

    while(1)
    {


            cout<<"\nEnter your choice\n";
            cout<<"\n1.Insert\n2.Delete\n3.Search\n4.Display\n5.Exit\n";
            cin>>option;
            switch(option)
            {
                          case 1:cout<<"\nEnter the value your want to insert\n";
                                 cin>>key;
                                 ih.insert(key);
                                 break;
                          case 2:cout<<"\nEnter the value you want to delete\n";
                                 cin>>key;
                                 ih.del(key);
                                 break;
                          case 3:cout<<"\nEnter the value you want to search\n";
                                 cin>>key;
                                 ans=ih.search(key);
                                 if(ans)
                                  cout<<"\nFound\n";
                                  else
                                  cout<<"\nMissing\n";
                                 break;
                          case 4:ih.display();
                                  break;
                          case 5:exit(1);
            }
    }
return 0;
}


OUTPUT:-

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
1

Enter the value your want to insert
2

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
1

Enter the value your want to insert
4

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
1

Enter the value your want to insert
6

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
4
NULL
NULL
2
NULL
4
NULL
6
NULL
NULL
NULL

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
3

Enter the value you want to search
4

Found

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
2

Enter the value you want to delete
6

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
4
NULL
NULL
2
NULL
4
NULL
NULL
NULL
NULL
NULL

Enter your choice

1.Insert
2.Delete
3.Search
4.Display
5.Exit
5

Sunday, 23 October 2011

Program for Quick Sort


#include<iostream>
#include<cstdlib>
using namespace std;
class sort
{
        int a[20],b[20];
        int low,high;
        public:
                int n;
                int get();
                void getdata();
                void quicksort(int,int);
                void display();

};
void sort::getdata()
{
        cout<<"enter the number of elements in the array";
        cin>>n;
        cout<<"enter the elements";
        for(int i=0;i<n;i++)
                cin>>b[i];
}
int sort::get()
{
   return n;
}
void sort::quicksort(int low,int high)
{
    int p,i,j,t;
    p=i=low,j=high;
    if(i<j)
    {
       while(i<j)
       {
          while(b[p]<b[j])
            j--;
            if(b[p]>b[j])
              {
                 t=b[p];
                 b[p]=b[j];
                 b[j]=t;
                 p=j;
              }
                while(b[p]>b[i])
                    i++;
                   if(b[p]<b[i])
                   {
                        t=b[i];
                        b[i]=b[p];
                        b[p]=t;
                        p=i;
                   }
                        if(i>=j)
                         {
                             quicksort(low,i-1);
                             quicksort(i+1,high);
                         }
        }
     }
}
void sort::display()
{
        cout<<"the sorted list is\n";
        for(int i=0;i<n;i++)
                                               {
                cout<<b[i]<<"\t";
        }
}
int main()
{
        sort a;
        int op;
        while(1)
        {
                cout<<"enter the option\n";
                cout<<"1.get data\n2.quick sort\n3.display\n4.exit\n";
                cin>>op;
                switch(op)
                {
                        case 1:
                                a.getdata();
                                break;
                        case 2:
                                a.get();
                                a.quicksort(0,a.n-1);
                                break;
                        case 3:
                                a.display();
                                break;
                        case 4:
                                exit(1);
                }
        }
}


OUTPUT:-

enter the option
1.get data
2.quick sort
3.display
4.exit
1
enter the number of elements in the array5
enter the elements2
1
3
6
7
enter the option
1.get data
2.quick sort
3.display
4.exit
3
the sorted list is
2       1       3       6       7       enter the option
1.get data
2.quick sort
3.display
4.exit
2
enter the option
1.get data
2.quick sort
3.display
4.exit
3
the sorted list is
1       2       3       6       7       enter the option
1.get data
2.quick sort
3.display
4.exit
4