Would you help to fix the problem in lines from 31 to 39? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Would you help to fix the problem in lines from 31 to 39?

In the header file there are methods etc. for Binary Search Tree as map in c language of programming. This is the header file : https://code.sololearn.com/cbBRQc5kIklU/#c And this is the map.c file: https://code.sololearn.com/chRjOZNNGOLX/#c which I have problems in lines from 31 to 39? Would you please help to fix them?

6th Sep 2019, 11:04 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
6 Answers
+ 1
Hello. I think, its here: “if(mp!=NULL){...} else if(mp->value>val)....” if MP not NULL, you fill it, ok; but this IF has ELSE-branch, and you happen there when MP is NULL, and at this time try to get access by empty pointer -> error
6th Sep 2019, 7:57 PM
Dmitrii
+ 4
Dmitrii ok, seems understandable , would you tell the syntaxis of creating a new node?
7th Sep 2019, 6:04 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 3
Dmitrii so what shall we do?)
7th Sep 2019, 5:46 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 3
Dmitrii how do we make sure that key-value pair is created successfully ?
7th Sep 2019, 6:08 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 1
so, is no need to check equality mp and null, but check equality mp->root and null is a good idea in order to understand, does map empty. In another case, you should create new tree node and connect it to suitable node to left or right
7th Sep 2019, 6:00 AM
Dmitrii
+ 1
you have it in function which creates new map, when you create root, just realize that 3 lines as function and use it in define function
7th Sep 2019, 6:07 AM
Dmitrii