Linux.com

sarath.sridhar

sarath.sridhar

  • Linux.com Member
  • Posts: 2
  • Member Since: 06 Apr 11
  • Last Logged In: 01 Apr 12

Latest Posts

Posted by
Topic
Post Preview
Posted
  • sarath.sridhar
    RE: HELP... error in my simple binary search program
    #include #include #include struct tree { int data ; struct tree *left,*right; }*root, *T=NULL; typedef struct tree *node; node insert(int,node t); node FindMin(node t); node del(int,node t); void display(node t); int main() { int item,n,i; char c; printf("\nenter the number of elemnets in tree..:"); scanf("%d",&n); printf("\nenter the elements:\n"); for(i=1;i<=n;i++) { scanf("%d",&item); T=insert(item,T); } printf("\nelements displayed in inorder:\n"); display(T); printf("\nenter the elements to delete:\n"); scanf("%d",&item); T=del(item,T); printf("\ncontents of tree after deletion:\n"); display(T); } node insert(int x, node T) { struct tree *temp; temp=malloc(sizeof(struct tree)); if(temp==NULL) printf("\nout of space"); else { if(T==NULL) { temp->data=x; temp->left=temp->right=NULL; T=temp; } else { if(xdata) T->left=insert(x,T->left); else T->right=insert(x,T->right); } } return T; } node del(int x, node T) { node temp; if(T==NULL) printf("\nelement not found"); else { if(xdata) T->left=del(x,T->left); else if(x>T->data) T->right=del(x,T->right); else if(T->left && T->right) { temp=FindMin(T->right); T->data=temp->data; T->right=del(T->data,T->right); } else { temp=T; if(T->left==NULL) T=T->right; else if(T->right==NULL) T=T->left; free(temp); } } return T; } node FindMin(node T) { if(T!=NULL) { if(T->left==NULL) return T; else return FindMin(T->left); } } void display(node T) { if(T!=NULL) { display(T->left); printf("%d\n",T->data); display(T->right); } }
    Link to this post 07 Apr 11

    #include<stdio.h>
    #include<stdlib.h>
    #include<malloc.h>
    struct tree
    {
    int data ;
    struct tree *left,*right;
    }*root, *T=NULL;
    typedef struct tree *node;
    node insert(int,node t);
    node FindMin(node t);
    node del(int,node t);
    void display(node t);
    int main()
    {
    int item,n,i;
    char c;
    printf("\nenter the number of elemnets in tree..:");
    scanf("%d",&n);
    printf("\nenter the elements:\n");
    for(i=1;i<=n;i++)
    {
    scanf("%d",&item);
    T=insert(item,T);
    }
    printf("\nelements displayed in inorder:\n");
    display(T);
    printf("\nenter the elements to delete:\n");
    scanf("%d",&item);
    T=del(item,T);
    printf("\ncontents of tree after deletion:\n");
    display(T);
    }
    node insert(int x, node T)
    {
    struct tree *temp;
    temp=malloc(sizeof(struct tree));
    if(temp==NULL)
    printf("\nout of space");
    else
    {
    if(T==NULL)
    {
    temp->data=x;
    temp->left=temp->right=NULL;
    T=temp;
    }
    else
    {
    if(x<T->data)
    T->left=insert(x,T->left);
    else
    T->right=insert(x,T->right);
    }
    }
    return T;
    }
    node del(int x, node T)
    {
    node temp;
    if(T==NULL)
    printf("\nelement not found");
    else
    {
    if(x<T->data)
    T->left=del(x,T->left);
    else
    if(x>T->data)
    T->right=del(x,T->right);
    else
    if(T->left && T->right)
    {
    temp=FindMin(T->right);
    T->data=temp->data;
    T->right=del(T->data,T->right);
    }
    else
    {
    temp=T;
    if(T->left==NULL)
    T=T->right;
    else
    if(T->right==NULL)
    T=T->left;
    free(temp);
    }
    }
    return T;
    }
    node FindMin(node T)
    {
    if(T!=NULL)
    {
    if(T->left==NULL)
    return T;
    else
    return FindMin(T->left);
    }
    }
    void display(node T)
    {
    if(T!=NULL)
    {
    display(T->left);
    printf("%d\n",T->data);
    display(T->right);
    }
    }

  • sarath.sridhar
    i need big help to create a touchscreen app
    hello I am trying to create a touch screen application for a restaurant. I need your guide from the basic. I dont have any idea about the operating system for this application and tools. I want to finish this project within 3 months. Please help me. Thanks in advance
    Link to this post 07 Apr 11

    hello

    I am trying to create a touch screen application for a restaurant. I need your guide from the basic. I dont have any idea about the operating system for this application and tools. I want to finish this project within 3 months. Please help me. Thanks in advance

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board