/*
#include <stdio.h>
int main()
{
tNode* root=NULL;
tNode* keyNode=NULL;
return 0;
}
*/
/*
#include <stdio.h>
#include <malloc.h>
typedef struct Dnode_
{
int data;
struct Dnode_ *llink, *rlink;
} Dnode;
Dnode* init(int k)
{
Dnode *tmp=(Dnode*)malloc(sizeof(Dnode*));
tmp->data=k;
tmp->llink=tmp;
tmp->rlink=NULL;
return tmp;
}
void insertNode(Dnode *root, int key)
{
Dnode *newNode=init(key);
if(root==NULL)
{
root=newNode;
return ;
}
newNode->rlink=root->rlink;
root->rlink=newNode;
newNode->llink=root;
if(newNode->rlink!=NULL) newNode->rlink->llink=newNode;
}
void printNode()
{
Dnode *tmp, *head;
while(tmp!=NULL)
{
printf("%d ", tmp->data);
tmp=tmp->rlink;
}
printf("\n");
}
int main()
{
int i, key;
Dnode *head=init(key);
for(i=0;i<10;i++) {
insertNode(head, i);
printNode();
}
return 0;
}
*/
/*
#include <stdio.h>
#include <malloc.h>
typedef struct Dnode_
{
int data;
struct Dnode_ *llink, *rlink;
} Dnode;
Dnode* init(int k)
{
Dnode *tmp=(Dnode*)malloc(sizeof(Dnode*));
tmp->data=k;
tmp->llink=tmp;
tmp->rlink=NULL;
return tmp;
}
void searchNode()
{
Dnode *root;
root-
}
void insertNode(Dnode *root, int key)
{
Dnode *newNode=init(key);
if(root==NULL)
{
root=newNode;
return ;
}
newNode->rlink=root->rlink;
root->rlink=newNode;
newNode->llink=root;
if(newNode->rlink!=NULL) newNode->rlink->llink=newNode;
}
void printNode()
{
Dnode *tmp, *head;
while(tmp!=NULL)
{
printf("%d ", tmp->data);
tmp=tmp->rlink;
}
printf("\n");
}
int main()
{
int i, key;
Dnode *head=init(key);
return 0;
}
*/
#include <stdio.h>
typedef struct treeNode_ {
int key;
struct treeNode_ *left, *right;
}treeNode;
treeNode* insertNode(treeNode *p, int x)
{
treeNode *newNode;
if(p==NULL) {
newNode=(treeNode*)malloc(sizeof(treeNode*));
newNode->key=x;
newNode->left=NULL;
newNode->right=NULL;
return newNode;
}
else if(x<p->key)
p->left=insertNode(p->left, x);
else if(x>p->key)
p->right=insertNode(p->right, x);
else printf("\nerror\n");
return p;
}
void deleteNode(treeNode *root, int key)
{
treeNode *parent, *child, *p, *succ, *succ_parent;
parent=NULL;
p=root;
while((p!=NULL)&&(p->key!=key)) {
parent=p;
if(key<p->key) p=p->left;
else p=p->right;
}
if(p==NULL) {
printf("\nerror\n");
return;
}
if((p->left==NULL)&&(p->right==NULL)) {
if(parent!=NULL) {
if(parent!=NULL) {
if(parent->left==p) parent->left=NULL;
else parent->right=NULL;
}
else root=NULL;
}
}
else if((p->left==NULL)||(p->right==NULL)) {
if(p->left!=NULL) child=p->left;
else child=p->right;
if(parent!=NULL) {
if(parent->left==p) parent->left=child;
else parent->right=child;
}
else root=child;
}
else {
succ_parent=p;
succ=p->left;
while(succ->right!=NULL) {
succ_parent=succ;
succ=succ->right;
}
if(succ_parent->left==succ) succ_parent->left=succ->left;
else succ_parent->right=succ->left;
p->key=succ->key;
p=succ;
}
free(p);
}
int main()
{
}