Facebook
From ja, 4 Years ago, written in C++.
This paste is a reply to kochamciedawid from ja - view diff
Embed
Download Paste or View Raw
Hits: 305
  1. // MergeSort 30.08 0055.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
  2. //
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. struct node
  9. {
  10.         int val;
  11.         node* next;
  12. };
  13.  
  14. void add(node*& H, int x)
  15. {
  16.         node* p = new node;
  17.         p->val = x;
  18.         p->next = H;
  19.         H = p;
  20. }
  21.  
  22. void del(node*& H)
  23. {
  24.        
  25.         if (H != NULL)
  26.         {
  27.                 node* p = H;
  28.                 H = H->next;
  29.                 delete p;
  30.         }
  31. }
  32.  
  33. int count(node*& H)
  34. {
  35.         node* p = H;
  36.         int n = 1;
  37.         while (p != NULL)
  38.         {
  39.                 n++;
  40.                 p = p->next;
  41.         }
  42.         return n;
  43. }
  44.  
  45. int half(node*& H, int x)
  46. {
  47.         if (H != NULL)
  48.         {
  49.                 node* slow = H;
  50.                 count(x);
  51.                 for (int i = 0; i < x; i++)
  52.                 {
  53.                         slow = slow->next;
  54.                 }
  55.  
  56.         }
  57.         return slow;  //potrzebuje zwrocic wskaznik na element ktory jest polowa listy
  58. }
  59.  
  60. void show(node* H)
  61. {
  62.         node* p = H;
  63.         if (H != NULL)
  64.         {
  65.                 node* p = H;
  66.                 cout << "->" << p->val;
  67.                 H = H->next;
  68.         }
  69.         else
  70.                 cout << "NULL" << endl;
  71. }
  72.  
  73. void merge(node*& H)
  74. {
  75.        
  76.         node* front = H;
  77.         int x = half(H, count(H));
  78. }
  79.  
  80. int main()
  81. {
  82.    
  83. }
  84.  
  85.