Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1.  
  2.     public static void Merge(Dane[] D, int begin, int q, int end, Dane[] temp)
  3.     {
  4.         int copied= 0;
  5.         int copied1= begin;
  6.         int copied2= q;
  7.        
  8.        
  9.         while((copied1<=q)&&(copied2<=end))
  10.             if((D[copied1].value)<=(D[copied2].value))
  11.             {
  12.                 D[1].countOfSimilise++;
  13.                 D[(copied1)].countOfExchange++;
  14.                
  15.                 temp[copied].value= D[(copied1)].value;
  16.                 temp[copied].beginPosition= D[(copied1)].beginPosition;
  17.                 temp[copied].countOfExchange= D[(copied1)].countOfExchange;
  18.                
  19.                
  20.                 copied++;
  21.                 copied1++;
  22.                
  23.             }
  24.             else
  25.             {
  26.                 D[1].countOfSimilise++;
  27.                 D[(copied2)].countOfExchange++;
  28.                
  29.                 temp[copied].value= D[(copied2)].value;
  30.                 temp[copied].beginPosition= D[(copied2)].beginPosition;
  31.                 temp[copied].countOfExchange= D[(copied2)].countOfExchange;
  32.                
  33.                
  34.                 copied++;
  35.                 copied2++;
  36.             }
  37.        
  38.         while (copied1<=q)
  39.         {
  40.             temp[copied].value= D[(copied1)].value;
  41.             temp[copied].beginPosition= D[(copied1)].beginPosition;
  42.            
  43.             temp[copied].countOfExchange= D[(copied1)].countOfExchange;
  44.            
  45.             if (copied!=copied1)
  46.                 temp[copied].countOfExchange++;
  47.            
  48.             copied++;
  49.             copied1++;
  50.         }
  51.        
  52.         while (copied2<=end)
  53.         {
  54.             temp[copied].value= D[(copied2)].value;
  55.             temp[copied].beginPosition= D[(copied2)].beginPosition;
  56.            
  57.             temp[copied].countOfExchange= D[(copied2)].countOfExchange;
  58.            
  59.             if (copied!=copied2)
  60.                 temp[copied].countOfExchange++;
  61.            
  62.             copied++;
  63.             copied2++;
  64.             }
  65.         int f; 
  66.         for (int i=0; i<end-begin+1; i++)
  67.         {
  68.             f=begin+i;
  69.             D[f].value= temp[i].value;
  70.             D[f].beginPosition= temp[i].beginPosition;
  71.             D[f].countOfExchange= temp[i].countOfExchange;
  72.            
  73.         }
  74.         }  
  75.    
  76.     public static void MergeSort(Dane[] D, int begin, int end, Dane[] temp) //begin= zerowy element +1
  77.     {
  78.         int q;
  79.         q=(begin+end)/2;
  80.        
  81.            
  82.         if (begin<end)
  83.         {
  84.             MergeSort(D, begin, q, temp);
  85.             MergeSort(D, q+1, end, temp);
  86.            
  87.             Merge(D, begin, q, end, temp);
  88.         }
  89.         Merge(D, begin, q, end, temp);
  90.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement