online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */ class Solution { public: vector<int> nextLargerNodes(ListNode* head) { if(head==NULL){ vector <int> v; return v; } if(head->next==NULL){ vector <int> v(1,0); return v; } else{ stack <int> s; vector<int> arr; ListNode* temp = head; while(temp!=NULL){ arr.push_back(temp->val); temp = temp->next; } vector<int> v(arr.size(),0); for(int i=arr.size()-1;i>=0;i--){ if(s.empty()){ v[i] = -1; } else if(s.size()>0 and s.top>arr[i]){ v[i] = s.top(); } else{ while(s.size()>0 and s.top()<=arr[i]){ s.pop(); } if(s.empty()){ v[i] = -1; } else{ v[i] = s.top(); } } s.push(arr[i]); } return v; } } };

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue