Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. struct Item {
  2.     int data;
  3.     struct Item *next;
  4. };
  5.  
  6.  
  7.  
  8. Item *sortList(Item *head) {
  9.  
  10.     Item *current = head;
  11.     int size = 0;
  12.  
  13.     while (current != NULL) {
  14.         size++;
  15.         current = current->next;
  16.     }
  17.  
  18.     int *temp = new int[size];
  19.     int j = 0;
  20.  
  21.     current = head;
  22.  
  23.     while (current != NULL) {
  24.         temp[j++] = current->data;
  25.         current = current->next;
  26.     }
  27.  
  28.     sortArr(temp, size);
  29.     freeList(head);
  30.     head = NULL;
  31.  
  32.     for (int i = size - 1; i >= 0; i--) {
  33.         head = add(head, temp[i]);
  34.     }
  35.  
  36.     delete[] temp;
  37.     return head;
  38. }
  39.  
  40.  
  41. Item *sortList2(Item *head) {
  42.  
  43.     Item *current = head;
  44.    
  45.  
  46.     while (current != NULL) {
  47.        
  48.  
  49.  
  50.     }
  51.  
  52.  
  53.     return head;
  54. }
  55.  
  56.  
  57. int main() {
  58.  
  59.     Item *head1 = NULL;
  60.     Item *head2 = NULL;
  61.  
  62.     head1 = add(head1, 15);
  63.     head1 = add(head1, 11);
  64.     head1 = add(head1, 9);
  65.     head1 = add(head1, 6);
  66.     head1 = add(head1, 5);
  67.     head1 = add(head1, 2);
  68.     head1 = add(head1, 1);
  69.  
  70.     head2 = add(head2, 15);
  71.     head2 = add(head2, 6);
  72.     head2 = add(head2, 5);
  73.     head2 = add(head2, 4);
  74.     head2 = add(head2, 2);
  75.  
  76.     Item *res = sortList(head1);
  77.     printList(res);
  78.  
  79.  
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement