Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void szukanie_inwersyjne()
- {
- std::vector<AnsiString> vstr;
- std::vector<bool> vbool;
- std::vector<std::vector<lista*>> element;
- std::vector<lista*> wstawiany(1, NULL); //1 ELEMENT O WARTOSCI NULL
- short choice = Form4 -> ComboBox1 -> ItemIndex;
- int x;
- int place;
- lista* tmp = pocz;
- if (choice != 2 && choice != 5)
- {
- Application->MessageBox(L"Nie można wyszukać inwersyjnie dla kolumny bez powtarzających się wartości", L":(", MB_OK | MB_ICONSTOP);
- return;
- }
- while (tmp != NULL)
- {
- switch (choice)
- {
- case 2:
- place = placestring(vstr, tmp -> typ);
- if (place != -1)
- {
- element[place].push_back(tmp);
- }
- else
- {
- vstr.push_back(tmp -> typ);
- wstawiany[0] = tmp;
- element.push_back(wstawiany);
- }
- break;
- case 5:
- place = placebool(vbool, tmp -> automatyczna);
- if (place != -1)
- {
- element[place].push_back(tmp);
- }
- else
- {
- vbool.push_back(tmp -> automatyczna);
- wstawiany[0] = tmp;
- element.push_back(wstawiany);
- }
- break;
- }
- tmp = tmp -> nast;
- }
- // SORTOWANIE --------------------
- AnsiString vstr_tmp;
- bool vbool_tmp;
- int j;
- std::vector <lista*> element_tmp;
- for(int i = 1; i < element.size(); i++)
- {
- element_tmp = element[i];
- vstr_tmp = vstr[i];
- j = i - 1;
- while(j >= 0 && vstr[j] > vstr_tmp)
- {
- vstr[j + 1] = vstr[j]; // NIE SORTUJE BOOL, BO JEST TO MNIEJ OPTYMALNE NIŻ OPERACJA BEZ POSORTOWANIA I MA TYLKO 2 OPCJE
- element[j + 1] = element[j];
- j--;
- }
- element[j + 1] = element_tmp;
- vstr[j + 1] = vstr_tmp;
- }
- // *******
- if (choice == 5)
- {
- if (Form4 -> Edit1 -> Text.UpperCase() == "TAK")
- vbool_tmp = true;
- else if (Form4 -> Edit1 -> Text.UpperCase() == "NIE")
- vbool_tmp = false;
- else
- {
- Application->MessageBox(L"Zła wartość!", L":(", MB_OK | MB_ICONSTOP);
- return;
- }
- }
- else vstr_tmp = Form4 -> Edit1 -> Text.UpperCase();
- for (x = 0; x < element.size(); x++)
- {
- if (((choice == 2) && vstr_tmp == vstr[x].UpperCase()) || ((choice == 5) && vbool_tmp == vbool[x]))
- break;
- }
- if (x == element.size())
- {
- Application -> MessageBox(L"NIE ZNALEZIONO.", L"Info", MB_OK | MB_ICONINFORMATION);
- return;
- }
- AnsiString automat[2] = {"Nie", "Tak"};
- Form4 -> StringGrid1 -> RowCount = 2;
- for (j = 0; j <element[x].size(); j++) {
- Form4 -> StringGrid1 -> RowCount++;
- Form4 -> StringGrid1 -> Cells[0][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> ID;
- Form4 -> StringGrid1 -> Cells[1][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> typ;
- Form4 -> StringGrid1 -> Cells[2][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> nazwa;
- Form4 -> StringGrid1 -> Cells[3][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> masa;
- Form4 -> StringGrid1 -> Cells[4][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> wiek;
- Form4 -> StringGrid1 -> Cells[5][Form4 -> StringGrid1 -> RowCount - 2] = automat[element[x][j] -> automatyczna];
- Form4 -> StringGrid1 -> Cells[6][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> cena;
- Form4 -> StringGrid1 -> Cells[7][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> kaliber;
- Form4 -> StringGrid1 -> Cells[8][Form4 -> StringGrid1 -> RowCount - 2] = element[x][j] -> kraj;
- }
- Form4 -> StringGrid1 -> Cells[0][Form4 -> StringGrid1 -> RowCount - 1] = "";
- Form4 -> StringGrid1 -> Cells[1][Form4 -> StringGrid1 -> RowCount - 1] = "";
- Form4 -> StringGrid1 -> Cells[2][Form4 -> StringGrid1 -> RowCount - 1] = "";
- Form4 -> StringGrid1 -> Cells[3][Form4 -> StringGrid1 -> RowCount - 1] = "";
- Form4 -> StringGrid1 -> Cells[4][Form4 -> StringGrid1 -> RowCount - 1] = "";
- Form4 -> StringGrid1 -> Cells[5][Form4 -> StringGrid1 -> RowCount - 1] = "";
- Form4 -> StringGrid1 -> Cells[6][Form4 -> StringGrid1 -> RowCount - 1] = "";
- Form4 -> StringGrid1 -> Cells[7][Form4 -> StringGrid1 -> RowCount - 1] = "";
- Form4 -> StringGrid1 -> Cells[8][Form4 -> StringGrid1 -> RowCount - 1] = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement