After Hours

General discussion


BST insertion ( protection exception error)

By ruksu88 ·
Tags: Off Topic
Hi ,

I have written a prog to insert elements in binary search tree...

wen i run the prog I have got an error i.e general protection exception, processor fault...

Pls help me to find wats the error and how to resolve it...

here is the prog


struct node{
struct node * left;
int val;
struct node * right;
} *root;

//create node and return its adress
struct node * create_node(int x)
struct node * new_node = (struct node *)malloc(sizeof(struct node));
new_node->val = x;
return new_node;

//function to insert values in BST
void ins(struct node *temp, int x)
if(temp->val == x){printf("\nduplicate value\n");}
if(x < temp->val)
{ printf("\ngoing left\n");
if(temp->left == NULL){
temp->left = create_node(x);
if(temp->left){printf("\nnew node created and its value is %d\n",temp->left->val);}
else{ins(temp->left, x);}
printf("\ngoing right\n");
if(temp->right == NULL){temp->right = create_node(x); }
else{ins(temp->right, x);}
return ;

void main()
int val,label;

do {

case 1 : printf("enter value\n");
scanf("%d",&val); //printf("\nvalue u entered is %d\n",val);
if(root == NULL)
root = create_node(val);
printf("\nfirst value inserted as root \n");
ins(root, val);

case 2 : printf("\ndelete");

default : exit(0);
}while (label<=2);


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Repost as 'Q&A'

by HAL 9000 Moderator In reply to BST insertion ( protectio ...

Try reposting this in the 'Q&A' forum. The 'Discussion' forum is for matters of general discussion, not specific problems in search of a solution. The 'Water Cooler' is for non-technical discussions. You can submit a question to 'Q&A' here:;content

There are TR members who specifically seek out problems in need of a solution. Although there is some overlap between the forums, you'll find more of those members in 'Q&A' than in 'Discussions' or 'Water Cooler'.

Be sure to use the voting buttons to provide your feedback. Voting a '+' does not necessarily mean that a given response contained the complete solution to your problem, but that it served to guide you toward it. This is intended to serve as an aid to those who may in the future have a problem similar to yours. If they have a ready source of reference available, perhaps won't need to repeat questions previously asked and answered. If a post did contain the solution to your problem, you can also close the question by marking the helpful post as "The Answer".

Related Discussions

Related Forums