#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Data { char name[25]; }
struct Tnode { Tnode* left=NULL, right=NULL; Data d; }
struct BST {
private :
    Tnode *root=NULL;
public :
    Tnode* getRoot() { return root; }
    void setRoot(Tnode *t) { root=t; }
    Tnode* insertNode(Tnode *t, Data d);
    void deleteNode(Tnode *p, Tnode *t, Data d);
    Tnode* minP(Tnode *p, Tnode *t);
    void printNode(Tnode *t, int m);
}
Tnode* BST::insertNode(Tnode *t, Data d) {
    if(t==NULL) {
        t=(Tnode*)malloc(sizeof(Tnode));
        t->d=d;
        t->left=t->right=NULL;
    }
    else if(strcmp(t->d.name, d.name)<0) t->left=insertNode(t->left, d); 
    else t->right=insertNode(t->right, d);
    return t;
}

int main() {
    int n, m, k;
    Data d;
    BST bst;
    scanf("%d %d", &n, &m);
    for(int i=0; i<n; i++) {
        scanf("%d %s", &k, d.name);
        if(k==1)
            bst.setRoot(bst.insertNode(bst.getRoot(), d));
        else 
            bst.deleteNode(NULL, bst.getRoot(), d);
    }
    bst.printNode(bst.getRoot(), m);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: