Saturday, 3 October 2015

Binary search Tree in c/c++ source code, Binary search tree, source code,

Binary search Tree in c/c++ source code, Binary search tree, source code,
// bin search 22.cpp : Defines the entry point for the console application.
//



For More:>  Sorting......, selection sort..., merge sort....., insertion Sort....., General Tree.... and many more......







#include "stdafx.h"

#include <iostream.h>
#include <process.h> //for exit(1)
#include <conio.h>

struct node{
    int data;
    struct node *left;
    struct node *right;
};

class BST{
    public:
    node *tree;
    BST(){
        tree=NULL;
    }
    void createTree(node **,int item);    //For Building Tree
void preOrder(node *);     //For Tree Traversal
void inOrder(node *);
    void postOrder(node *);

    void determineHeight(node *,int *);
    int totalNodes(node *);
    int internalNodes(node *); //no. of non-leaf nodes
int externalNodes(node *); //no. of leaf nodes.
void removeTree(node **); //Remove tree from memory.

    node **searchElement(node **,int);
    void findSmallestNode(node *);
    void findLargestNode(node *);
    void deleteNode(int);
};


//it is used for inseting an single element in//a tree, but if calls more than once will create tree.
void BST :: createTree(node **tree,int item){
    if(*tree == NULL){
        *tree = new node;
        (*tree)->data = item;
        (*tree)->left = NULL;
        (*tree)->right = NULL;
    }
    else{
        if( (*tree)->data > item)
            createTree( &((*tree)->left),item);
        else
            createTree( &((*tree)->right),item);
    }
}


void BST :: preOrder(node *tree){
    if( tree!=NULL){
        cout<<"   "<< tree->data;
        preOrder(tree->left);
        preOrder(tree->right);
    }
}

void BST :: inOrder(node *tree){
    if( tree!=NULL){
        inOrder( tree->left);
        cout<<"   "<< tree->data;
        inOrder(tree->right);
    }
}


void BST :: postOrder(node *tree){
    if( tree!=NULL){
        postOrder( tree->left);
        postOrder( tree->right);
        cout<<"   "<<tree->data;
    }
}


void BST :: determineHeight(node *tree, int *height){
    int left_height, right_height;
    if( tree == NULL)
        *height = 0;
    else{
        determineHeight(tree->left, &left_height);
        determineHeight(tree->right, &right_height);
        if( left_height > right_height)
            *height = left_height + 1;
        else
            *height = right_height + 1;
    }
}


int BST :: totalNodes(node *tree){
    if( tree == NULL)
        return 0;
    else return( totalNodes(tree->left) + totalNodes(tree->right) + 1 );
}

int BST :: internalNodes(node *tree){
    if( (tree==NULL)  || (tree->left==NULL  && tree->right==NULL))
        return 0;
    else return( internalNodes(tree->left) + internalNodes(tree->right) + 1 );
}

int BST :: externalNodes(node *tree){
    if( tree==NULL )
        return 0;
    else 
if( tree->left==NULL  && tree->right==NULL)
        return 1;
    else return( externalNodes(tree->left) + externalNodes(tree->right));
}

void BST :: removeTree(node **tree){
    if( (*tree) != NULL)
{
        removeTree( &(*tree)->left );
        removeTree( &(*tree)->right );
        delete( *tree );
    }
}

node ** BST :: searchElement(node **tree, int item){
    if( ((*tree)->data == item) || ( (*tree) == NULL) )
        return tree;
    else if( item < (*tree)->data);
        return searchElement( &(*tree)->left, item)
    else return searchElement( &(*tree)->right, item)
}

void BST :: findSmallestNode(node *tree){
    if( tree==NULL || tree->left==NULL)
        cout<< tree->data;
    else
        findSmallestNode( tree->left);
}


//Finding In_order Successor of given node..//for Delete Algo.
node * find_Insucc(node *curr)
{
    node *succ=curr->right; //Move to the right sub-tree.
if(succ!=NULL){
        while(succ->left!=NULL)    //If right sub-tree is not empty.
            succ=succ->left; //move to the left-most end.
    }
    return(succ);
}


void BST :: findLargestNode(node *tree){
    if( tree==NULL || tree->right==NULL)
        cout<<tree->data;
    else
        findLargestNode(tree->right);
}


void BST :: deleteNode(int item){
    node *curr=tree,*succ,*pred;
    int flag=0,delcase;
    //step to find location of node
while(curr!=NULL && flag!=1)
    {
        if(item < curr->data){
            pred = curr;
            curr = curr->left;
        }
        elseif(item > curr->data){
            pred = curr;
            curr = curr->right;
        }
        else{ //curr->data = item
            flag=1;
        }
    }

    if(flag==0){
        cout<<"\nItem does not exist : No deletion\n";
        getch();
        goto end;
    }

    //Decide the  case of deletion
if(curr->left==NULL && curr->right==NULL)
        delcase=1; //Node has no child
else
if(curr->left!=NULL && curr->right!=NULL)
        delcase=3; //Node contains both the child
else
        delcase=2; //Node contains only one child//Deletion Case 1
if(delcase==1){
        if(pred->left == curr) //if the node is a left child
            pred->left=NULL; //set pointer of its parent
else
            pred->right=NULL;
        delete(curr); //Return deleted node to the memory bank.
    }

    //Deletion Case 2
if(delcase==2){
        if(pred->left==curr){ //if the node is a left child
if(curr->left==NULL)
                pred->left=curr->right;
            else
                pred->left=curr->left;
        }
        else{ //pred->right=curr
if(curr->left==NULL)
                pred->right=curr->right;
            else
                pred->right=curr->left;
        }
        delete(curr);
    }

    //Deletion case 3
if(delcase==3){
        succ = find_Insucc(curr); //Find the in_order successor//of the node.
int item1 = succ->data;
        deleteNode(item1);  //Delete the inorder successor
        curr->data = item1; //Replace the data with the data of//in order successor.
    }
end:
}



void main(){
    BST obj;
    int choice;
    int height=0,total=0,n,item;
    node **tmp;

    while(1){
        clrscr();
        cout<<"*****BINARY SEARCH TREE OPERATIONS*****\n\n";
        cout<<"--Binary Tree and Binary Search Tree common operations--\n";
        cout<<"1) Create Tree\n";
        cout<<"2) Traversal\n";
        cout<<"3) Height of Tree\n";
        cout<<"4) Total Nodes\n";
        cout<<"5) Internal Nodes \n";
        cout<<"6) External Nodes \n";
        cout<<"7) Remove Tree\n";
        cout<<"\n--Only Binary Search Tree Operations--\n";
        cout<<"8)  Insert Node\n";
        cout<<"9)  Search Node\n";
        cout<<"10) Find Smallest Node\n";
        cout<<"11) Find Largest Node\n";
        cout<<"12) Delete Node\n";
        cout<<"13) Exit\n";
        cout<<"Enter your choice : ";
        cin>>choice;
        switch(choice){
            case 1 : //Create Tree
                cout<<"\n\n--Creating Tree--";
                cout<<"\nHow many nodes u want to enter : ";
                cin>>n;
                for(int i=0;i<n;i++){
                    cout<<"Enter value : ";
                    cin>>item;
                    obj.createTree(&obj.tree,item);
                }
                break;

            case 2 : //All Traversals
                cout<<"\n\nInorder Traversal : ";
                obj.inOrder(obj.tree);

                cout<<"\n\nPre-order Traversal : ";
                obj.preOrder(obj.tree);

                cout<<"\n\nPost-order Traversal : ";
                obj.postOrder(obj.tree);
                getch();
                break;

            case 3 : //Determining Height of Tree
                obj.determineHeight(obj.tree,&height);
                cout<<"\n\nHeight of Tree : "<<height;
                getch();
                break;

            case 4 : //Total nodes in a tree
                total=obj.totalNodes(obj.tree);
                cout<<"\n\nTotal Nodes : "<<total;
                getch();
                break;

            case 5 : //Internal nodes in a tree
                total=obj.internalNodes(obj.tree);
                cout<<"\n\nInternal Nodes : "<<total;
                getch();
                break;

            case 6 : //External nodes in a tree
                total=obj.externalNodes(obj.tree);
                cout<<"\n\nExternal Nodes : "<<total;
                getch();
                break;

            case 7 : //Remove Tree from memory
                obj.removeTree(&obj.tree);
                cout<<"\n\nTree is removed from Memory";
                getch();
                break;

            case 8 : //Inserting a node in a tree
                cout<<"\n\n--Inserting Node in a tree--\n";
                cout<<"Enter value : ";
                cin>>item;
                obj.createTree(&obj.tree,item);
                cout<<"\nItem is inserted\n";
                getch();
                break;

            case 9 : //Search element
                cout<<"\n\n--Search Element--\n";
                cout<<"Enter item to searched : ";
                cin>>item;
                &(*tmp) = obj.searchElement(&obj.tree,item);
                if( (*tmp) == NULL)
                    cout<<"\nSearch Element Not Found";
                else
                    cout<<"\nSearch Element was Found";
                getch();
                break;

            case 10 : //Find Smallest Node
                cout<<"\n\nSmallest Node is :  ";
                obj.findSmallestNode(obj.tree);
                getch();
                break;

            case 11 : //Find Largest Node
                cout<<"\n\nLargest Node is :  ";
                obj.findLargestNode(obj.tree);
                getch();
                break;

            case 12 : //Deleting a node from a tree
                cout<<"\n\n--Deleting a Node from a tree--\n";
                cout<<"Enter value : ";
                cin>>item;
                obj.deleteNode(item);
                break;

            case 13 : exit(1);
        }//end of switch
    }
}
Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com 

Monday, 28 September 2015

Html font styles Bold and Italic in urdu/hindi, html video tutorials,

Html font styles Bold and Italic in urdu/hindi,  html video tutorials,
Html font styles Bold and Italic in urdu/hindi,  html video tutorials,
Html font styles Bold and Italic in urdu/hindi,  html video tutorials,



Html font styles Bold and Italic in urdu/hindi,  html video tutorials,
Html font styles Bold and Italic in urdu/hindi,  html video tutorials,

SMART MESSAGING APP, Top android final year project ideas, android ideas, android final year project ideas,

SMART MESSAGING APP, Top android final year project ideas, android ideas, android final year project ideas,
SMART MESSAGING APP 












I guess have you heard about WhatsApp, Line, IMO etc. It comes under the smart messaging app. You can also create app like these for your final year android project. You can add feature to your app according to your requirement. 

I just want to build something which make me happy. You can gave the feature to your app.

 Single Chatting 
 Group Chatting 
 You Can Share any type of file under 100 MB
 Instant chatting.  Ring notification for someone when he will call you.
 Voice chatting

Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com 

REMINDER APPLICATION ANDROID PROJECT, Top android final year project ideas, android ideas, android final year project ideas,

Top android final year project ideas, android ideas, android final year project ideas,
REMINDER APPLICATION ANDROID PROJECT











It is coolest and my favorite app suggestion for beginner. To make this project you need not any database programming simple android API knowledge is sufficient. There are many great example of reminder app available in Google Play Store. You can find there and test on your smart phone or tablet. I believe perfection never exit. See the example and find the cons and improve that cons in your app. Your android app will be better.

Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com 

QUIZ APPLICATION ANDROID PROJECT, Top android final year project ideas, android ideas, android final year project ideas,

Top android final year project ideas, android ideas, android final year project ideas,
QUIZ APPLICATION ANDROID PROJECT











For Beginner level you can make Quiz application android project. It will be easy for you if you don't know how to do database programming. You can do simply this application without using database. But I don't like it without online database connectivity. Wait don't be confuse. I am simplifying it. 

Quiz Application Android App without online database connectivity. In this android project you need not to connect you android app with your online database. it will be easier for beginner and I don't like it. Because you have to fix limited number of question. Once user install your app. There will be no control on your hand.

Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com

B Trees in c/c++ source code, Trees source code in c/c++, source code,

B Trees in c/c++ source code, Trees source code in c/c++, source code,
// btrees.cpp : Defines the entry point for the console application.
//



B Trees in c/c++ source code, Trees source code in c/c++, source code, 

For More:>  Sorting......, selection sort..., merge sort....., insertion Sort....., General Tree....Binary Tree..... and many more.....



#include "stdafx.h"

/*A program to implement B-TREE.
   */

#include<iostream>
using namespace std;


class node;
struct pair
{
int key;
node *next;
}pair;
class node
{
public:
node *father;
int noofkeys;
    pair data[MAX];
node *first;
node();
void insert_in_node(pair x);
pair splitnode(pair x);
int leaf_node();
node *nextindex(int x);
void display();
};
void node::display()
{
int i;
cout<<"(";
for(i=0;i<noofkeys;i++)
cout<<data[i].key<<" ";
cout<<")";
}
node* node::nextindex(int x)
{
if(x<data[0].key)
return first;
for(int i=0;i<noofkeys;i++)
{
if(x<=data[i].key)
return (data[i-1].next);
}
return (data[i-1].next);
}
int node::leaf_node()
{
if(data[0].next==NULL)
return 1;
return 0;
}


 void node::insert_in_node(pair mypair)
   {
int i;
for(i=noofkeys-1;i>=0 && data[i].key>mypair.key;i--)
data[i+1]=data[i];
data[i+1]=mypair;
noofkeys++;
   }

node::node()
{
 for(int i=0;i<=MAX;i++)
  data[i].next=NULL;
 noofkeys=0;
 father=NULL;
 first=NULL;
}

class btree
 {
int mkeys;
node *root;
public:
btree(int n)
  {
mkeys=n;
root=NULL;
  }
void insert(int x);
void displaytree();
 };

void main()
   {
 int n,i,x,op;
 node *p;

 cout<<"\nmaximum number of keys in a node ? :";
 cin>>n;
 btree b(n);
 do
{
cout<<"\n\n1)Insert\n2)Print\n3)Quit";
cout<<"\nEnter your choice : ";
cin>>op;
switch(op)
  {
case 1: cout<<"\nEnter a data : ";
cin >> x;
b.insert(x);
break;

case 2:
b.displaytree();
  break;
}
 }while(op!=3);
}

Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com 

Wednesday, 23 September 2015

Safe array in c/c++ source code, Array source code in c/c++, source code,

Safe array in c/c++ source code, Array source code in c/c++, source code,
// safe_arry.cpp : Defines the entry point for the console application.
//


Safe array in c/c++ source code, 

For More:>  Sorting......, selection sort..., merge sort....., insertion Sort....., General Tree....Binary Tree..... and many more......









#include<iostream.h>

int const size=10;


class safe_array
{
int array[size];
public:

safe_array()
{
for(int i=0;i<size;i++)
{
array[i]=0;
}
}



 void put(int f,int no)
 {
if(f>=0&&f<=size-1)
{

array[f]=no;
}
else{
cout<<"execed size:";
}
 }

 int get(int no)
 {
if(no>=0&&no<=size-1)
{
int a=array[no];
cout<<a<<endl;
return a;
}
else
{
return 0;
}
 }

 void input()
 {
for(int i=0;i<size;i++)
{
cout<<"enter no";
cin>>array[i];
}
 }

 void output()
 {
for(int i=0;i<size;i++)
{
cout<<array[i]<<endl;
}
 }

 safe_array adding(safe_array a)
 {
safe_array b;
for(int i=0;i<size;i++)
{
  b.array[i]=a.array[i]+array[i];
}
return b;
 }



 int search_array(int a)
 {

    for(int i=0;i<=size;i++)
{
if(array[i]==a)
{
return i;

}
}
 }
 void sort_array()
 {
for(int i=0;i<=size;i++)
{
for(int j=0;j<=size-1;j++)
{
if(array[j+1]<array[j])
{
int temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
 }
};




int main()
{
safe_array arr,b,c;

char a;
do
{

cout<<"------------------------------------------"<<endl;
cout<<"enter 'A' for put in array:"<<endl;
cout<<"enter 'B' for get from array:"<<endl;
cout<<"enter 'C' for whole input:"<<endl;
cout<<"enter 'D' for whole display:"<<endl;
cout<<"enter 'E' for adding two objects:"<<endl;
cout<<"enter 'F' for search:"<<endl;
cout<<"enter 'G' for sort:"<<endl;
cout<<"enter 'I' for Exit:"<<endl;
cout<<"-----------------------------------------------"<<endl;

cout<<"enter choice:";
cin>>a;
switch (a)
{
case 'A':
          int n,k;
  cout<<"enter index=";
  cin>>k;
  cout<<"enter value=";
  cin>>n;
  arr.put(k,n);

break;

case 'B':
          int m;
  cout<<"enter index=";
  cin>>m;
  arr.get(m);
  
break;
case 'C':
arr.input();

break;
case 'D':
  arr.output();

break;
case 'E':
     
 b.input();
c= arr.adding(b);
c.output();
break;

case 'F':
int l,s;
cout<<"enter number for search";
cin>>l;
s=arr.search_array(l);
cout<<"number is at index:"<<s;
break;
case 'G':
arr.sort_array();

break;

}
}while(a!='I');

return 0;
}


Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com

LinkWithin