Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. void szukanie_inwersyjne()
  2. {
  3.  
  4. std::vector<AnsiString> vstr;
  5. std::vector<bool> vbool;
  6. std::vector<std::vector<lista*>> element;
  7. std::vector<lista*> wstawiany(1, NULL); //1 ELEMENT O WARTOSCI NULL
  8. short choice = Form4 -> ComboBox1 -> ItemIndex;
  9. int x;
  10. int place;
  11. lista* tmp = pocz;
  12.  
  13. if (choice != 2 && choice != 5)
  14. {
  15. Application->MessageBox(L"Nie można wyszukać inwersyjnie dla kolumny bez powtarzających się wartości", L":(", MB_OK | MB_ICONSTOP);
  16. return;
  17. }
  18.  
  19. while (tmp != NULL)
  20. {
  21. switch (choice)
  22. {
  23. case 2:
  24. place = placestring(vstr, tmp -> typ);
  25. if (place != -1)
  26. {
  27. element[place].push_back(tmp);
  28. }
  29. else
  30. {
  31. vstr.push_back(tmp -> typ);
  32. wstawiany[0] = tmp;
  33. element.push_back(wstawiany);
  34. }
  35. break;
  36. case 5:
  37. place = placebool(vbool, tmp -> automatyczna);
  38. if (place != -1)
  39. {
  40. element[place].push_back(tmp);
  41. }
  42. else
  43. {
  44. vbool.push_back(tmp -> automatyczna);
  45. wstawiany[0] = tmp;
  46. element.push_back(wstawiany);
  47. }
  48. break;
  49. }
  50. tmp = tmp -> nast;
  51. }
  52.  
  53. // SORTOWANIE --------------------
  54.  
  55. AnsiString vstr_tmp;
  56. bool vbool_tmp;
  57. int j;
  58. std::vector <lista*> element_tmp;
  59.  
  60. for(int i = 1; i < element.size(); i++)
  61. {
  62. element_tmp = element[i];
  63. vstr_tmp = vstr[i];
  64.  
  65. j = i - 1;
  66. while(j >= 0 && vstr[j] > vstr_tmp)
  67. {
  68. vstr[j + 1] = vstr[j]; // NIE SORTUJE BOOL, BO JEST TO MNIEJ OPTYMALNE NIŻ OPERACJA BEZ POSORTOWANIA I MA TYLKO 2 OPCJE
  69. element[j + 1] = element[j];
  70. j--;
  71. }
  72.  
  73. element[j + 1] = element_tmp;
  74. vstr[j + 1] = vstr_tmp;
  75. }
  76.  
  77. // *******
  78.  
  79. if (choice == 5)
  80. {
  81. if (Form4 -> Edit1 -> Text.UpperCase() == "TAK")
  82. vbool_tmp = true;
  83. else if (Form4 -> Edit1 -> Text.UpperCase() == "NIE")
  84. vbool_tmp = false;
  85. else
  86. {
  87. Application->MessageBox(L"Zła wartość!", L":(", MB_OK | MB_ICONSTOP);
  88. return;
  89. }
  90. }
  91. else vstr_tmp = Form4 -> Edit1 -> Text.UpperCase();
  92.  
  93.  
  94. for (x = 0; x < element.size(); x++)
  95. {
  96. if (((choice == 2) && vstr_tmp == vstr[x].UpperCase()) || ((choice == 5) && vbool_tmp == vbool[x]))
  97. break;
  98. }
  99.  
  100. if (x == element.size())
  101. {
  102. Application -> MessageBox(L"NIE ZNALEZIONO.", L"Info", MB_OK | MB_ICONINFORMATION);
  103. return;
  104. }
  105. AnsiString automat[2] = {"Nie", "Tak"};
  106. Form4 -> StringGrid1 -> RowCount = 2;
  107.  
  108. for (j = 0; j <element[x].size(); j++) {
  109. Form4 -> StringGrid1 -> RowCount++;
  110. Form4 -> StringGrid1 -> Cells[0][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> ID;
  111. Form4 -> StringGrid1 -> Cells[1][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> typ;
  112. Form4 -> StringGrid1 -> Cells[2][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> nazwa;
  113. Form4 -> StringGrid1 -> Cells[3][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> masa;
  114. Form4 -> StringGrid1 -> Cells[4][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> wiek;
  115. Form4 -> StringGrid1 -> Cells[5][Form4 -> StringGrid1 -> RowCount - 2] = automat[element[x][j] -> automatyczna];
  116. Form4 -> StringGrid1 -> Cells[6][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> cena;
  117. Form4 -> StringGrid1 -> Cells[7][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> kaliber;
  118. Form4 -> StringGrid1 -> Cells[8][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> kraj;
  119. }
  120. Form4 -> StringGrid1 -> Cells[0][Form4 -> StringGrid1 -> RowCount - 1] = "";
  121. Form4 -> StringGrid1 -> Cells[1][Form4 -> StringGrid1 -> RowCount - 1] = "";
  122. Form4 -> StringGrid1 -> Cells[2][Form4 -> StringGrid1 -> RowCount - 1] = "";
  123. Form4 -> StringGrid1 -> Cells[3][Form4 -> StringGrid1 -> RowCount - 1] = "";
  124. Form4 -> StringGrid1 -> Cells[4][Form4 -> StringGrid1 -> RowCount - 1] = "";
  125. Form4 -> StringGrid1 -> Cells[5][Form4 -> StringGrid1 -> RowCount - 1] = "";
  126. Form4 -> StringGrid1 -> Cells[6][Form4 -> StringGrid1 -> RowCount - 1] = "";
  127. Form4 -> StringGrid1 -> Cells[7][Form4 -> StringGrid1 -> RowCount - 1] = "";
  128. Form4 -> StringGrid1 -> Cells[8][Form4 -> StringGrid1 -> RowCount - 1] = "";
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement