#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int value;
struct node * left;
struct node * right;
} Node;
Node *
newNode( int n) {
Node* obj;
obj
= ( Node
* ) malloc ( sizeof ( Node
) ) ; obj-> value = n;
obj-> left = NULL;
obj-> right = NULL;
return obj;
}
Node *
addNode( Node* obj, int n) {
Node * iobj;
if ( obj == NULL) {
return newNode( n) ;
}
iobj = obj;
while ( 1 ) {
if ( iobj-> value == n) {
break ;
} else if ( iobj-> value < n) {
if ( iobj-> right == NULL) {
iobj-> right = /* (10) */ ;
break ;
} else {
iobj = iobj-> right;
}
} else {
if ( iobj-> left == NULL) {
iobj-> left = newNode( n) ;
break ;
} else {
iobj = iobj-> left;
}
}
}
return obj;
}
Node *
deleteThisNode( Node * obj) {
Node * tmpobj;
Node * iobj;
if ( obj == NULL) return NULL;
if ( obj-> left == NULL) {
tmpobj = obj-> right;
} else if ( obj-> right == NULL) {
tmpobj = obj-> left;
} else {
tmpobj = obj-> left;
iobj = tmpobj;
while ( iobj-> right != NULL) {
iobj = iobj-> right;
}
iobj-> right = /* (11) */ ;
}
return tmpobj;
}
Node *
deleteNode( Node * obj, int n) {
Node * pobj;
if ( obj-> value == n) {
obj = deleteThisNode( obj) ;
return obj;
} else {
pobj = obj;
while ( 1 ) {
if ( pobj-> value < n) {
if ( pobj-> right == NULL) {
break ;
} else {
if ( pobj-> right-> value== n) {
pobj-> right = /* (12) */ ;
break ;
} else {
pobj = pobj-> right;
}
}
} else {
if ( pobj-> left == NULL) {
break ;
} else {
if ( pobj-> left-> value == n) {
pobj-> left = deleteThisNode( pobj-> left) ;
break ;
} else {
pobj = /* (13) */ ;
}
}
}
}
}
}
void
printNodes( Node * obj) {
if ( obj != NULL) {
if ( obj-> left != NULL) {
printNodes( obj-> left) ;
}
if ( obj-> right != NULL) {
printNodes( obj-> right) ;
}
}
}
int
main( int argc, char * argv[ ] ) {
Node * topnode = NULL;
topnode = addNode( topnode, 5 ) ;
topnode = addNode( topnode, 7 ) ;
topnode = addNode( topnode, 1 ) ;
topnode = addNode( topnode, - 1 ) ;
topnode = addNode( topnode, 4 ) ;
topnode = addNode( topnode, 10 ) ;
printNodes( topnode) ;
topnode = deleteNode( topnode, 5 ) ;
printNodes( topnode) ;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+Cgp0eXBlZGVmIHN0cnVjdCBub2RlewogIGludCB2YWx1ZTsKICBzdHJ1Y3Qgbm9kZSAqbGVmdDsKICBzdHJ1Y3Qgbm9kZSAqcmlnaHQ7Cn0gTm9kZTsKCk5vZGUgKgpuZXdOb2RlKGludCBuKXsKICBOb2RlKiBvYmo7CiAgb2JqID0gKE5vZGUgKiltYWxsb2Moc2l6ZW9mKE5vZGUpKTsKICBvYmotPnZhbHVlID0gbjsKICBvYmotPmxlZnQgPSBOVUxMOwogIG9iai0+cmlnaHQgPSBOVUxMOwogIHJldHVybiBvYmo7Cn0KCgpOb2RlICoKYWRkTm9kZShOb2RlKiBvYmosIGludCBuKXsKICBOb2RlICppb2JqOwoKICBpZihvYmogPT0gTlVMTCl7CiAgICByZXR1cm4gbmV3Tm9kZShuKTsKICB9CiAgaW9iaiA9IG9iajsKCiAgd2hpbGUoMSl7CiAgICBpZihpb2JqLT52YWx1ZSA9PSBuKXsKICAgICAgYnJlYWs7CiAgICB9ZWxzZSBpZihpb2JqLT52YWx1ZSA8IG4pewogICAgICBpZihpb2JqLT5yaWdodCA9PSBOVUxMKXsKCWlvYmotPnJpZ2h0ID0gLyogICAoMTApICAgKi87CglicmVhazsKICAgICAgfWVsc2V7Cglpb2JqID0gaW9iai0+cmlnaHQ7CiAgICAgIH0KICAgIH1lbHNlewogICAgICBpZiggaW9iai0+bGVmdCA9PSBOVUxMKXsKCWlvYmotPmxlZnQgPSBuZXdOb2RlKG4pOwoJYnJlYWs7CiAgICAgIH1lbHNlewoJaW9iaiA9IGlvYmotPmxlZnQ7CiAgICAgIH0KICAgIH0KICB9CiAgcmV0dXJuIG9iajsKfQoKCk5vZGUgKgpkZWxldGVUaGlzTm9kZShOb2RlICpvYmopewogIE5vZGUgKnRtcG9iajsKICBOb2RlICppb2JqOwoKICBpZihvYmogPT0gTlVMTCkgcmV0dXJuIE5VTEw7CiAgaWYob2JqLT5sZWZ0ID09IE5VTEwpewogICAgdG1wb2JqID0gb2JqLT5yaWdodDsKICAgIGZyZWUob2JqKTsKICB9ZWxzZSBpZihvYmotPnJpZ2h0ID09IE5VTEwpewogICAgdG1wb2JqID0gb2JqLT5sZWZ0OwogICAgZnJlZShvYmopOwogIH1lbHNlewoKICAgIHRtcG9iaiA9IG9iai0+bGVmdDsKCiAgICBpb2JqID0gdG1wb2JqOwogICAgd2hpbGUoaW9iai0+cmlnaHQgIT0gTlVMTCl7CiAgICAgIGlvYmogPSBpb2JqLT5yaWdodDsKICAgIH0KICAgIGlvYmotPnJpZ2h0ID0gLyogICAoMTEpICAgKi87CiAgICBmcmVlKG9iaik7CiAgfQogIHJldHVybiB0bXBvYmo7Cn0KCgpOb2RlICoKZGVsZXRlTm9kZShOb2RlICpvYmosIGludCBuKXsKICBOb2RlICogcG9iajsKCiAgaWYob2JqLT52YWx1ZSA9PSBuKXsKICAgIG9iaiA9IGRlbGV0ZVRoaXNOb2RlKG9iaik7CiAgICByZXR1cm4gb2JqOwogIH1lbHNlewoKICAgIHBvYmogPSBvYmo7CiAgICB3aGlsZSgxKXsKICAgICAgaWYocG9iai0+dmFsdWUgPCBuKXsKCWlmKHBvYmotPnJpZ2h0ID09IE5VTEwpewoJICBicmVhazsKCX1lbHNlewoJICBpZihwb2JqLT5yaWdodC0+dmFsdWU9PW4pewoJICAgIHBvYmotPnJpZ2h0ID0gLyogICAoMTIpICAgKi87CgkgICAgYnJlYWs7CgkgIH1lbHNlewoJICAgIHBvYmogPSBwb2JqLT5yaWdodDsKCSAgfQoJfQogICAgICB9ZWxzZXsKCglpZihwb2JqLT5sZWZ0ID09IE5VTEwpewoJICBicmVhazsKCX1lbHNlewoJICBpZihwb2JqLT5sZWZ0LT52YWx1ZSA9PSBuKXsKCSAgICBwb2JqLT5sZWZ0ID0gZGVsZXRlVGhpc05vZGUocG9iai0+bGVmdCk7CgkgICAgYnJlYWs7CgkgIH1lbHNlewoJICAgIHBvYmogPSAvKiAgICgxMykgICAqLzsKCSAgfQoJfQogICAgICB9CiAgICB9CiAgfQp9CgoKdm9pZApwcmludE5vZGVzKE5vZGUgKm9iail7CiAgaWYob2JqICE9IE5VTEwpewogICAgaWYob2JqLT5sZWZ0ICE9IE5VTEwpewogICAgICBwcmludE5vZGVzKG9iai0+bGVmdCk7CiAgICB9CgogICAgcHJpbnRmKCIlZFx0Iiwgb2JqLT52YWx1ZSk7CgogICAgaWYob2JqLT5yaWdodCAhPSBOVUxMKXsKICAgICAgcHJpbnROb2RlcyhvYmotPnJpZ2h0KTsKICAgIH0KICB9Cn0KCmludAptYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pewogIE5vZGUgKnRvcG5vZGUgPSBOVUxMOwoKCiAgdG9wbm9kZSA9IGFkZE5vZGUodG9wbm9kZSwgNSk7CiAgdG9wbm9kZSA9IGFkZE5vZGUodG9wbm9kZSwgNyk7CiAgdG9wbm9kZSA9IGFkZE5vZGUodG9wbm9kZSwgMSk7CiAgdG9wbm9kZSA9IGFkZE5vZGUodG9wbm9kZSwgLTEpOwogIHRvcG5vZGUgPSBhZGROb2RlKHRvcG5vZGUsIDQpOwogIHRvcG5vZGUgPSBhZGROb2RlKHRvcG5vZGUsIDEwKTsKCiAgcHJpbnROb2Rlcyh0b3Bub2RlKTsKICBwcmludGYoIlxuIik7CgogIHRvcG5vZGUgPSBkZWxldGVOb2RlKHRvcG5vZGUsIDUpOwoKICBwcmludE5vZGVzKHRvcG5vZGUpOwogIHByaW50ZigiXG4iKTsKfQ==
compilation info
prog.c: In function ‘addNode’:
prog.c:35: error: expected expression before ‘;’ token
prog.c: In function ‘deleteThisNode’:
prog.c:73: error: expected expression before ‘;’ token
prog.c: In function ‘deleteNode’:
prog.c:96: error: expected expression before ‘;’ token
prog.c:111: error: expected expression before ‘;’ token
stdout