fork download
  1. // Following is the node structure
  2. /**************
  3. class ListNode{
  4. public:
  5. int data;
  6. ListNode* next;
  7. };
  8.  
  9. ListNode* newListNode(int data){
  10. ListNode *temp = new ListNode;
  11.   temp->data = data;
  12.   temp->next = NULL;
  13.   return temp;
  14. }
  15. ***************/
  16.  
  17. ListNode* RemoveNodeWithGreaterLeft(ListNode *head) {
  18. /*Write your code here.
  19. *Don't write main().
  20. *Don't take input, it is passed as function argument.
  21. *Don't print output.
  22. *Taking input and printing output is handled automatically.
  23. */
  24.  
  25. if(head == NULL){
  26. return NULL;
  27. }
  28. if(head->next == NULL){
  29. return head;
  30. }
  31. ListNode *temp = head;
  32. ListNode *prev = NULL;
  33. while(temp->next!=NULL){
  34. prev = temp;
  35. temp = temp->next;
  36. if(prev->data > temp->data){
  37. prev->next = temp->next;
  38. }
  39.  
  40. }
  41. return head;
  42. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:17:1: error: ‘ListNode’ does not name a type
 ListNode* RemoveNodeWithGreaterLeft(ListNode *head) {
 ^~~~~~~~
stdout
Standard output is empty