Where is my code goes wrong?


#1

/
ListNode
Solution::subtract(ListNode* A) {
if(A==NULL|| A->next==NULL) return A;
else if(A->next->next==NULL)
{
A->val=A->next->val-A->val;
return A;
}
ListNode* p;
ListNode* q;ListNode* res=A;
p=A;q=A;
while(q->next->next!=NULL&&q->next!=NULL)
{
p=p->next;
q=q->next->next;
}
ListNode* temp=p->next;
if(q->next->next==NULL) p=p->next;
stacks;
while(temp!=NULL)
{
s.push(temp->val);
temp=temp->next;
}
while(!s.empty())
{
res->val=s.top()-res->val;
res=res->next;
s.pop();
}
res=p;
return A;
}


#2

5 7 9 is not giving any output and its is run time error