fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. struct ListNode {
  6. int val;
  7. ListNode *next;
  8. ListNode(int x) : val(x), next(NULL) {}
  9. };
  10.  
  11. class Solution {
  12. public:
  13. ListNode* reverseList(ListNode* head) {
  14. if(head ==NULL)
  15. return NULL;
  16. ListNode *p;
  17. p = head;
  18. while(p!=NULL)
  19. {
  20. list.push(p->val);
  21. p = p->next;
  22. }
  23. ListNode *result =&(ListNode(0));
  24.  
  25.  
  26. while(list.empty()!)
  27. {
  28. ListNode *temp = ListNode( list.pop) ;
  29. ;
  30. result->next = temp;
  31.  
  32.  
  33. }
  34.  
  35.  
  36. return result;
  37.  
  38.  
  39.  
  40. }
  41.  
  42. private:
  43. stack<int> list;
  44. };
  45. int main() {
  46. // your code goes here
  47. return 0;
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:43:5: error: 'stack' does not name a type
     stack<int> list;
     ^
prog.cpp: In member function 'ListNode* Solution::reverseList(ListNode*)':
prog.cpp:20:11: error: 'list' was not declared in this scope
           list.push(p->val);
           ^
prog.cpp:23:39: error: taking address of temporary [-fpermissive]
        ListNode *result =&(ListNode(0));
                                       ^
prog.cpp:26:14: error: 'list' was not declared in this scope
        while(list.empty()!)
              ^
prog.cpp:26:26: error: expected ')' before '!' token
        while(list.empty()!)
                          ^
prog.cpp:26:27: error: expected primary-expression before ')' token
        while(list.empty()!)
                           ^
stdout
Standard output is empty