BST insertion



I m Trying to make BSTand checking if node already there just
return ,trying to return 1
but here its returning 0 ,

lease help


// btree.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"





#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct Node
{
int data ;
struct Node *left ;
struct Node *right ;
} ;

int insert_node(struct Node **bt ,int num )
{
struct Node *tmp ;
if(*bt==NULL)
{
tmp=(struct Node *)malloc(sizeof(struct Node ));
*bt=tmp ;
(*bt)->data=num ;
(*bt)->left=NULL ;
(*bt)->right=NULL ;
}
else
{
if(num < (*bt)->data)
insert_node(&((*bt)->left),num);
else
{
if (num == (*bt)->data)
return 1 ;
else
if (num > (*bt)->data)
insert_node(&((*bt)->right),num);

}
}
return 0 ;
}


int _tmain(int argc, _TCHAR* argv[])
{

struct Node * bt =NULL ;
int arr[5]= { 1,2,3,4,4 } ;
for(int i = 0 ;i<5 ;i++)
{
int tmp=insert_node(&bt ,arr[i]) ;
if(tmp)
printf("%d Duplicate ", arr[i] );
}

getch();

return 0 ;

}
.



Relevant Pages

  • radix sort
    ... struct node *next; ... void freelist; ... int large_dig; ... kth digit of all no:s */ ...
    (comp.programming)
  • LinkedList Pointer (REPOST - diff version)
    ... struct node * next; ... No problem until you are dealing with a pointer variable. ... void Push(struct node** headRef, int newData); ... Given an int and a reference to the head pointer (i.e. a struct ...
    (comp.lang.c)
  • LinkedList Pointer (REPOST - diff version)
    ... struct node * next; ... No problem until you are dealing with a pointer variable. ... void Push(struct node** headRef, int newData); ... Given an int and a reference to the head pointer (i.e. a struct ...
    (comp.lang.c)
  • Re: free memory question
    ... pointer (ptr) dynamically allocated in function "test_free"? ... struct node* y; ... int main ... struct node* calc = NULL; ...
    (comp.lang.c)
  • qsmurf.c
    ... Commenting out the printfthat is called for each packet that is sent. ... sends to the Quake server, so about half the bandwidth is being used to tell you that each packet was sent. ... struct node *next; ... void sig_handler(int); ...
    (Bugtraq)