- #1
ma12
- 2
- 0
my program is not working properly after taking values it gets overflow
#include<stdio.h>
#include<conio.h>
void insert(struct node**, int);
struct node *ptr;
struct node
{
int data;
struct node *right;
struct node *left;
};
void main()
{
int will , i , num;
ptr = NULL;
ptr -> data = NULL;
printf("Enter the Number");
scanf("%d", &will);
for(i=0; i<will; i++)
{
printf("Enter the Item",&num);
insert(&ptr, num);
}
getche();
}
void insert(struct node **p, int num)
{
if( (*p) == NULL)
{
printf("Leaf node created");
(*p) -> left = NULL;
(*p) -> right = NULL;
(*p) -> data = num;
return;
}
else
{
if( num==(*p) -> data)
printf("Entered repeated values rejected");
return;
}
if(num < (*p) -> data)
{
printf("directed to left ");
insert ( &((*p) -> left) ,num);
}
else
{
printf("Directed to right");
insert( &((*p) -> right), num);
}
return;
}
#include<stdio.h>
#include<conio.h>
void insert(struct node**, int);
struct node *ptr;
struct node
{
int data;
struct node *right;
struct node *left;
};
void main()
{
int will , i , num;
ptr = NULL;
ptr -> data = NULL;
printf("Enter the Number");
scanf("%d", &will);
for(i=0; i<will; i++)
{
printf("Enter the Item",&num);
insert(&ptr, num);
}
getche();
}
void insert(struct node **p, int num)
{
if( (*p) == NULL)
{
printf("Leaf node created");
(*p) -> left = NULL;
(*p) -> right = NULL;
(*p) -> data = num;
return;
}
else
{
if( num==(*p) -> data)
printf("Entered repeated values rejected");
return;
}
if(num < (*p) -> data)
{
printf("directed to left ");
insert ( &((*p) -> left) ,num);
}
else
{
printf("Directed to right");
insert( &((*p) -> right), num);
}
return;
}