#include <iostream>
using namespace std;

struct node {
    string code; 
    node *left, *right; 
};
class BST {
	node *root=nullptr; 
public: 
	void Insert(node *&start, string key); 
	void Insert(string key);
	void show(node *start=nullptr, int level=0, string t="") {
		if (start) {
			if (start->left)
		    	show (start->left, level+1, "L:"); 
		    else cout << string((level+1)*2,' ') <<"LX"<<endl;
		    cout << string(level*2,' ') <<t << start->code <<endl; 
		    if (start->right) 
		    	show (start->right, level+1, "R:");
		    else cout << string((level+1)*2,' ') <<"RX"<<endl;
		}
        else show(root);
	}
};

void BST::Insert(node *&start, string key){
    if (start == NULL) {
        start = new node;
        start->code = key;
        start->left = start->right = NULL;
        printf("Inserting Morse Code -> %s\n",key.c_str());
    }
    else if (start->code<key)
        Insert (start->left, key); 
    else if (start->code>key) 
        Insert (start->right, key); 
    else cout<<"Duplicate"<<endl;
}

void BST::Insert(string key) {
	Insert(root, key); 
	/*
    node **start = &root;
    if (*start != NULL) {
    	if (start->code<key)
        for(int i = 0; i < key.length(); i++) {
            if (key[i] == '.') {
                start = &((*start)->left);
            } else if (key[i] == '-') {
                 start = &((*start)->right);
            }else {
                break;
            }
        	Insert(*start, key);
        }
    } else {
        Insert(root, key);
    }*/
}

int main() {
	BST b;
	b.Insert(".-");
	b.Insert("-...");
	b.Insert("-.-.");
	b.Insert(".");
	b.show();
	return 0;
}