Guest User

Untitled

a guest
Apr 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. struct Node
  2. {
  3. int data;
  4. struct Node *next;
  5. }
  6.  
  7. struct Node* MergeLists(struct Node *headA,struct Node* headB)
  8. {
  9. if(headA==NULL) return headB;
  10. if(headB==NULL) return headA;
  11. if(headA==NULL && headB==NULL) return NULL;
  12.  
  13. if(headA->data < headB->data)
  14. {
  15. headA->next=MergeLists(headA->next,headB);
  16. return headA;
  17. }
  18. else
  19. {
  20. headB->next=MergeLists(headA,headB->next);
  21. return headB;
  22. }
  23. }
  24.  
  25. struct Node
  26. {
  27. int data;
  28. struct Node *next;
  29. }
  30.  
  31. Node* MergeLists(Node *headA, Node* headB)
  32. {
  33. if(headA==NULL) return headB;
  34. if(headB==NULL) return headA;
  35. if(headA==NULL && headB==NULL) return NULL;
  36. while(headA!=NULL && headB!=NULL)
  37. {
  38. if(headA->data>headB->data)
  39. {
  40. return headB;
  41. headB=headB->next;/*O problema está aqui preciso retornar o valor menor e ao mesmo tempo avançar a lista*/
  42. }else
  43. {
  44. return headA;
  45. headA=headA->next;/*O problema está aqui preciso retornar o valor menor e ao mesmo tempo avançar a lista com o return antes ele irá sair sem avançar*/
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment