Exemple #1
0
        public void set_knap(int[] weight, int[] cost, int R)
        {
            this.R = R;

            elements = new element[weight.Length];
            for (int i = 0; i < weight.Length; i++)
            {
                double c = cost[i];
                c = c / weight[i];
                elements[i] = new element(i, cost[i], weight[i], c);
            }
        }
Exemple #2
0
 public void quickSort_number(ref element[] a, int l, int r)
 {
     element temp;
     double x = a[l + (r - l) / 2].get_number();
     //запись эквивалентна (l+r)/2,
     //но не вызввает переполнения на больших данных
     int i = l;
     int j = r;
     //код в while обычно выносят в процедуру particle
     while (i <= j)
     {
         while (a[i].get_number() < x) i++;
         while (a[j].get_number() > x) j--;
         if (i <= j)
         {
             temp = a[i];
             a[i] = a[j];
             a[j] = temp;
             i++;
             j--;
         }
     }
     if (i < r)
         quickSort_number(ref a, i, r);
     if (l < j)
         quickSort_number(ref a, l, j);
 }