Advertisement
kej

Untitled

kej
Nov 10th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. //header
  2. public:
  3. UporList();
  4. UporList Merge(UporList A, UporList B);
  5. void OrderList();
  6. };
  7. //.cs
  8. UporList::UporList() : List()
  9. {
  10. top = new node;
  11. marker = top;
  12. }
  13.  
  14. UporList UporList::Merge(UporList A, UporList B) {
  15. UporList C;
  16. C.Reset();
  17. for (node* tmp = A.top; tmp != NULL; tmp=tmp->next)
  18. {
  19. if (tmp->next == NULL)
  20. {
  21. break;
  22. }
  23. // cout<<"Debug: "<< tmp->data << "\n";
  24. C.Add(tmp->data);
  25. }
  26. for (node* tmp = B.top; tmp != NULL; tmp=tmp->next)
  27. {
  28. if (tmp->next == NULL)
  29. {
  30. break;
  31. }
  32. C.Add(tmp->data);
  33. }
  34. C.OrderList();
  35. return C;
  36. }
  37. void UporList::OrderList() {
  38. node *left = top;
  39. node *right = top->next;
  40.  
  41. node *temp = new node;
  42.  
  43. while (left->next){
  44. while (right)
  45. {
  46. if ((left->data) < (right->data)){
  47. temp->data = left->data;
  48. left->data = right->data;
  49. right->data = temp->data;
  50. }
  51. right = right->next;
  52. }
  53. left = left->next;
  54. right = left->next;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement