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* ReverseBlocks(ListNode *head, int blocksize[], int length) {
  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. ListNode *curr = head;
  25. ListNode *prev = NULL;
  26. ListNode *next = NULL;
  27. int count = 0;
  28. for(int i = 0;i<length;i++){
  29. while(curr!=NULL && count<blocksize[i]){
  30. next = curr->next;
  31. curr->next = prev;
  32. prev = curr;
  33. curr = next
  34. }
  35. if(next!=NULL){
  36. head->next = ReverseBlocks(next,blocksize[i+1],length);
  37. }
  38. }
  39. head = prev;
  40. return head;
  41. }
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* ReverseBlocks(ListNode *head, int blocksize[], int length) {
 ^~~~~~~~
stdout
Standard output is empty