Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int w;
- int *tab = new int[w];
- void generowanie_tablicy(int w, int *tab);
- void wyswietlenie_tablicy(int w, int *tab);
- void sortowanie_babelkowe(int w, int *tab);
- void sortowanie_przez_wstawianie(int w, int *tab);
- int main()
- {
- bool menu=true;
- cout << "^^^^^^^^Budowanie tablicy^^^^^^^^^" << endl << endl;
- int w, metoda;
- cout << endl << endl << "Podaj liczbe elementow tablicy: ";
- cin >> w;
- generowanie_tablicy(w, tab);
- cout << "^^^^^^^^Tabela losowych liczb zostala utworzona^^^^^^^^" << endl << endl;
- system("PAUSE");
- system("CLS");
- while(menu)
- {
- cout << endl << "Wybierz co chcesz zrobic:" << endl << endl;
- cout << "1- wyswietlenie tabeli losowych liczb" << endl;
- cout << "2- dodawanie elementu na koniec" << endl;
- cout << "3- sortowanie babelkowe" << endl;
- cout << "4- sortowanie mieszane" << endl;
- cout << "5- sortowanie przez wybor" << endl;
- cout << "6- sortowanie przez proste wstawianie" << endl;
- cout << "7- sortowanie przez binarne wstawianie" << endl;
- cout << "8- wypisywanie tablicy po 10 elementow" << endl << endl;
- cout << "9- zakonczenie programu"<<endl;
- cin >> metoda;
- switch (metoda)
- {
- case 1: system("CLS"); wyswietlenie_tablicy(w, tab); break;
- case 2: system("CLS"); break;
- case 3: system("CLS"); wyswietlenie_tablicy(w, tab); sortowanie_babelkowe(w, tab); break;
- case 4: system("CLS"); cout << "4- sortowanie mieszane"; break;
- case 5: system("CLS"); cout << "5- sortowanie przez wybor"; break;
- case 6: system("CLS"); wyswietlenie_tablicy(w, tab); sortowanie_przez_wstawianie(w, tab); break;
- case 7: system("CLS"); cout << "7- sortowanie przez binarne wstawianie"; break;
- case 8: system("CLS"); cout << "8- wypisywanie tablicy po 10 elementow"; break;
- case 9:menu=false; break;
- default: system("CLS"); cout << "Blednie wybrales - ponow probe z zakresu 1-8"; ; break;
- }
- }
- getchar();
- cin.ignore();
- return 0;
- }
- void generowanie_tablicy(int w, int *tab)
- {
- for (int i = 0; i<w; i++)
- {
- tab[i] = rand() % 99 - 0;
- }
- cout << endl << endl;
- }
- void wyswietlenie_tablicy(int w, int *tab)
- {
- cout << "^^^^^^^^tabela losowych liczb^^^^^^^^" << endl << endl;
- for (int i = 0; i<w; i++)
- {
- cout << setw(4) << tab[i];
- }
- cout << endl << endl;
- }
- void sortowanie_babelkowe(int w, int *tab)
- {
- cout << "^^^^^^^^tabela po sortowaniu babelkowym^^^^^^^^" << endl << endl;
- for (int i = 0; i < w; i++)
- {
- for (int j = 0; j<w - i - 1; j++)
- if (tab[j]>tab[j + 1])
- {
- int z = tab[j];
- tab[j] = tab[j + 1];
- tab[j + 1] = z;
- }
- }
- for (int i = 0; i < w; i++)
- {
- cout << setw(4) << tab[i];
- }
- }
- void sortowanie_przez_wstawianie(int w, int *tab)
- {
- cout << "^^^^^^^^tabela po sortowaniu przez proste wstawianie^^^^^^^^" << endl << endl;
- for (int i = w - 2; i >= 0; i--)
- {
- int z = tab[i];
- int j = i + 1;
- while ((j<w) && (z>tab[j]))
- {
- tab[j - 1] = tab[j];
- j++;
- }
- tab[j - 1] = z;
- }
- for (int i = 0; i<w; i++)
- cout << setw(4) <<tab[i];
- cout << endl << endl << "Sortowanie przez wstawianie polega na wstawiamu" << endl << "liczby w odpowiednie miejsce przesuwajac pozostaee, nastepna"
- << endl << "takze wstawiamy miedzy odpowiednie karty i tak ukladamy zestaw" << endl << "liczb.Sorotwanie to jest podobne do ukladania kart.";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement