Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. namespace ClassLibrary5 {
  2.     void Class1::outputText(int value, TextBox^ t) {
  3.         t->Text = Convert::ToString(value);
  4.     }
  5.  
  6.  
  7.     void Class1::outputArray(int arrLen, int* arr, DataGridView^ grid) {
  8.         grid->ColumnCount = arrLen;
  9.         grid->RowCount = 2;
  10.         int width = 0;
  11.         for (int i = 0; i < arrLen; i++) {
  12.             grid->Rows[0]->Cells[i]->Value = "[" + Convert::ToString(i) + "]";
  13.             grid->Rows[1]->Cells[i]->Value = arr[i];
  14.             width += grid->Columns[i]->Width;
  15.         }
  16.         if (width > 410) {
  17.             grid->Width = 410;
  18.         }
  19.         else
  20.         {
  21.             grid->Width = width;
  22.         }
  23.     }
  24.  
  25.  
  26.     void Class1::generateArray(int arrLen, int* arr) {
  27.         for (int i = 0; i < arrLen; i++) {
  28.             arr[i] = int(rand() % 1001);
  29.         }
  30.     }
  31.  
  32.  
  33.     int Class1::getCount(int arrLen, int* arr) {
  34.         int count = 0;
  35.         for (int i = 0; i < arrLen - 1; i++) {
  36.             if ((arr[i] - arr[i + 1]) % 7 != 0) {
  37.                 count++;
  38.             }
  39.         }
  40.         return count;
  41.     }
  42.  
  43.  
  44.     void Class1::replaceElements(int arrLen, int count, int* arr, int* newArr, int &j) {
  45.         int elementCount = 0;
  46.         for (int i = 0; i < arrLen; i++) {
  47.             if (arr[i] > count) {
  48.                 elementCount++;
  49.             }
  50.         }
  51.         newArr[elementCount];
  52.         for (int i = 0; i < arrLen; i++) {
  53.             if (arr[i] > count) {
  54.                 newArr[j] = arr[i];
  55.                 j++;
  56.             }
  57.         }
  58.         for (int i = 0; i < arrLen; i++) {
  59.             if (arr[i] % 7 == 0) {
  60.                 arr[i] = count;
  61.             }
  62.         }
  63.     }
  64.  
  65.  
  66.     void Class1::sort6(int arrLen, int* arr) {
  67.         for (int i = 1; i < arrLen; i++) {
  68.             int j = i - 1;
  69.             int x = arr[i];
  70.             while (arr[j] > x && x >= 0) {
  71.                 arr[j + 1] = arr[j];
  72.                 j--;
  73.             }
  74.             arr[j + 1] = x;
  75.         }
  76.     }
  77.  
  78.  
  79.     void Class1::SortNumber5(int arrLen, int* arr) {
  80.         int MaxValue = 0;
  81.         int MinValue = 1000;
  82.         int indexMax = -1;
  83.         int indexMin = -1;
  84.         for (int i = 0; i < arrLen; i++) {
  85.             if (arr[i] > MaxValue) {
  86.                 MaxValue = arr[i];
  87.                 indexMax = i;
  88.             }
  89.             else if (arr[i] < MinValue) {
  90.                 MinValue = arr[i];
  91.                 indexMin = i;
  92.             }
  93.         }
  94.         arr[indexMin] = MaxValue;
  95.         arr[indexMax] = MinValue;
  96.     }
  97.  
  98.  
  99.     void Class1::sort92(int arrLen, int* arr) {
  100.         int flag = 1;
  101.         for (int i = arrLen - 1; i >= 0; i--) {
  102.             if (flag == 1) {
  103.                 flag = 0;
  104.                 for (int j = 1; j <= i; j++) {
  105.                     if (arr[j] > arr[j - 1]) {
  106.                         int temp = arr[j];
  107.                         arr[j] = arr[j - 1];
  108.                         arr[j - 1] = temp;
  109.                         flag = 1;
  110.                     }
  111.                 }
  112.             }
  113.             else {
  114.                 return;
  115.             }
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement