Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node* merge( Node* a , Node* b){
- Node* result = NULL;
- if (a == NULL)
- return (b);
- else if (b == NULL)
- return (a);
- if (a->data <= b->data) {
- result = a;
- result->next = Merge(a->next, b);
- }
- else {
- result = b;
- result->next = Merge(a, b->next);
- }
- return (result);
- }
- Node* sortList(Node* head) {
- if(!head || !head->next) return head;
- Node* slow = head;
- Node* fast =head->next;
- while(fast && fast->next){
- fast= fast->next->next;
- slow = slow->next;
- }
- Node* headb = slow->next;
- slow->next = NULL;
- return merge(sortList(head) , sortList(headb));
- }
Add Comment
Please, Sign In to add comment