// Decodes your encoded data to tree. TreeNode* deserialize(string data) { TreeNode* ans; queue<TreeNode*> q; stringstream ss (data); string str; ss >> str; popIt(str, q, ans); while (ss >> str) { TreeNode* par = q.front(); q.pop(); popIt(str, q, par->left); ss >> str; popIt(str, q, par->right); } return ans; }
char* decryptMsg(char *emsg) { char *dmsg = malloc(sizeof(emsg)); Node* list = malloc(sizeof(Node)); size_t n = 0; size_t m = 0; size_t l = 0; while (emsg[n]) { if (isdigit(emsg[n])) { //just getting an int from a char[], nothing to see here char* num; num = malloc(1024); size_t z = 0; while(isdigit(emsg[n])) { num[z++] = emsg[n++]; } dmsg[m++] = popIt(&list, atoi(num))->c; } else { //just put the letter dmsg[m++] = emsg[n]; insert(&list, emsg[n++]); } n++; } dmsg[m] = '\0'; return dmsg; }