Tree-double pointer

Discussion in 'C' started by Fika, Sep 1, 2010.

  1. Fika

    Fika New Member

    Joined:
    Sep 1, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I have one question about double pointers . For exemple inserting node in tree


    Code:
    int insert( cvor [B]**glava[/B] , char *name , float number ) {
    
            cvor *temp;
            int where ; 
    
            if ( *glava == NULL ) {
            temp = (cvor*)malloc(sizeof(cvor) ) ;
            if (temp == NULL ) printf("error");
            temp->left = temp->right = NULL ; 
            strcpy ( temp->name, name ) ;
            temp->number = number;
            *glava = temp ;
            return 1;
            } else { 
                    where = strcmp (name , (*glava)->name);
                    if ( !where ) return -1;
                    if ( where < 0 ) return dodaj( &((*glava)->left) , name , number ) ; 
                    return dodaj( &((*glava)->right) , name , number ) ; 
            }
    
    } 
    So why must be double pointer in this function (Bold) ? Or in creating list ?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice