Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. //Akshay Mandania
  2. //Doesnt work properly
  3. //Idea is there but my laptop battery was going to die and all my notes where on here
  4. //My plan was to create 2 linked lists and uses pointers to compare data between both lists and then remove greater value off the list and push it onto list 3. and then keep going. I was going to build an insertion sort for list3.
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. class SortingLists {
  10. public:
  11.  
  12. List list1;
  13. List list2;
  14. List list3;
  15.  
  16. void MergeLists(List list1, List list2) {
  17. Node *head;
  18. if (list1->data < list2->data) {
  19. head = list1;
  20. } else {
  21. head = list2;
  22. list2 = list1;
  23. list1 = head;
  24. }
  25.  
  26. while(list1->next != NULL) {
  27. if (list1->next->data > list2->data) {
  28. Node tmp = list1->next;
  29. list1->next = list2;
  30. list2 = tmp;
  31. }
  32. list1 = list1->next;
  33. }
  34. list1->next = list2;
  35. list3 = head;
  36. }
  37. };
  38. int main()
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement