Singledigit's blog

By Singledigit, history, 8 years ago, In English

Hello,

I have no idea how this is failing. It works perfectly fine from my terminal.

I am currently having a runtime error on Tree construction: http://codeforces.com/problemset/problem/675/D

g++ --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 7.3.0 (clang-703.0.29) Target: x86_64-apple-darwin15.4.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Error: Test: #1, time: 0 ms., memory: 2000 KB, exit code: -1073741819, checker exit code: 0, verdict: RUNTIME_ERROR Checker: null

Here are all my latest submissions: http://codeforces.com/submissions/Singledigit

Code

/* CodeForces Problem 675D
 * http://codeforces.com/problemset/problem/675/D
 * Objective: Create BST and Print out Parent nodes
 */
#include <vector>
#include <iostream>
using namespace std;

class tree{
   public: 
      long long val;
      tree *left, *right, *parent;
   public:
      tree(long long k, tree* l, tree* r){
         val = k;
         left = l;
         right = r;
      }
      tree(long long k, tree* p){
         val = k;
         left = right = NULL;
         parent = p;
      }
};

void insert(tree*& t, long long k, tree* p){
   if(t==NULL){
      t = new tree(k, p);
      if(p!=NULL) cout << p->val << " ";
      return;
   }else if(k > t->val){
      insert(t->right, k, t);
   }else if(k < t->val){
      insert(t->left, k, t);
   }
}

int main(){
   
   int size;
   cin >> size;
   tree* t;
   vector<long long> nodes;
   
   int i=0;
   while(i<size){
      long long temp; 
      cin>>temp;
      nodes.push_back(temp);
      i++;
   }

   for(i = 0;i<nodes.size();i++)
      insert(t,nodes.at(i), NULL);
   
   cout<<endl; 
   return 0;
}
  • Vote: I like it
  • +5
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

18098584

Your Run Time Error is gone now...

Try to debug your code for the wrong answer...

P.S Don't try to fix your code... You'll get Time Limit by this algorithm btw...