struct Node{ char data; int level; int l, r; Node(char data, int level){ this->data = data; this->level = level; l = -1; // NULL r = -1; } }; // static list vector<Node> v; // maxsize is 1024 queue<int> q[10]; // 1~9 level, store the index of the v map<char, int> m; // char2index
int findDeep(int ind, int deep){ // index, current deep Node node = v[ind]; int lDeep = deep, rDeep = deep;
int curIndex = v.size()-1; m[str[i]] = curIndex; q[level].push(curIndex);
// start to insert if(!q[level-1].empty()){ int fatherIndex = q[level-1].front(); if( v[fatherIndex].l == -1){ // the father node is empty v[fatherIndex].l = curIndex; } else{ v[fatherIndex].r = curIndex; q[level-1].pop(); // the father node is full } } }
// start to query string query; cin >> query; for(int i = 0; i < query.length(); i++){ if(m.find(query[i]) != m.end()){ int ind = m[query[i]];