Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Node
- {
- int data;
- struct Node *next;
- }
- struct Node* MergeLists(struct Node *headA,struct Node* headB)
- {
- if(headA==NULL) return headB;
- if(headB==NULL) return headA;
- if(headA==NULL && headB==NULL) return NULL;
- if(headA->data < headB->data)
- {
- headA->next=MergeLists(headA->next,headB);
- return headA;
- }
- else
- {
- headB->next=MergeLists(headA,headB->next);
- return headB;
- }
- }
- struct Node
- {
- int data;
- struct Node *next;
- }
- Node* MergeLists(Node *headA, Node* headB)
- {
- if(headA==NULL) return headB;
- if(headB==NULL) return headA;
- if(headA==NULL && headB==NULL) return NULL;
- while(headA!=NULL && headB!=NULL)
- {
- if(headA->data>headB->data)
- {
- return headB;
- headB=headB->next;/*O problema está aqui preciso retornar o valor menor e ao mesmo tempo avançar a lista*/
- }else
- {
- return headA;
- 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*/
- }
- }
- }
Add Comment
Please, Sign In to add comment