Works on my local environment, but got runtime exception at OJ.

• All my code is doing is a simple mergesort. Why is it generating a run time exception at OJ?
Last executed input: {2,1}

``````class List{
public:
ListNode* tl;

List(){}

List(vector<int>a){
ListNode* tmp = new ListNode(0);
for (int i = 0; i < a.size(); i++){
tmp->val = a[i];
if (i != a.size() - 1){
tmp->next = new ListNode(0);
tmp = tmp->next;
}
}
tl = tmp;
}

ListNode* n = new ListNode(v);
tl = n;
}
else{
tl->next = n;
tl = n;
}
}
};

class Solution {
public:
while (tmp->next != NULL){
tmp = tmp->next;
}
}

ListNode *mergeSort(ListNode* h, ListNode* t){

if (h == t){
return h;
}
else if (!h) return t;
else if (!t) return h;
//else if ()
else{

ListNode* tmp1 = new ListNode(0);
ListNode** backf = &tmp1;

ListNode* mid = getMiddle(h, t, backf);

ListNode* firstHalf = mergeSort(h, *backf);
ListNode* secondHalf = mergeSort(mid, t);
return merge(firstHalf, *backf, secondHalf, t);
}
}

// fully Tested
ListNode *merge(ListNode* fh, ListNode* ft, ListNode* sh, ListNode* st){
List list;
if (!fh || !sh) sh ? sh : fh;
else {
ListNode* ftmp = fh;
ListNode* stmp = sh;

bool passedFirstT = false;
bool passedSecondT = false;
while (!passedFirstT || !passedSecondT){
if (!passedFirstT && !passedSecondT && ftmp->val > stmp->val){
if (stmp == st) passedSecondT = true;
stmp = stmp->next;
}
else if (!passedFirstT && !passedSecondT && ftmp->val <= stmp->val){
if (ftmp == ft) passedFirstT = true;
ftmp = ftmp->next;
}
else if (passedFirstT){
if (stmp == st) passedSecondT = true;
stmp = stmp->next;
}
else {
if (ftmp == ft) passedFirstT = true;
ftmp = ftmp->next;
}
}

//assert(ft -> next == sh);
ft->next = sh;
ListNode* x = fh;

while (y){
x->val = y->val;
x = x->next;
y = y->next;
}
return fh;
}
}

ListNode *getMiddle(ListNode *head, ListNode* tail, ListNode** backf){
else{
while (mid != tail && mid){
*backf = tmph;
tmph = tmph->next;
mid = mid->next;
if (mid && mid != tail){
mid = mid->next;
}
}
return tmph;
}
}
};``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.