Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program ktory posortuje Tabele.
- #include <iostream>
- #include <conio.h>
- #include <ctime>
- using namespace std;
- void main()
- {
- srand((int) time(NULL));
- int x;
- int c = 0;
- int IloscZmian = 0;
- int Wielkosc;
- cout << "Podaj Wielkosc Tabeli: "; //Wybór Wielkości Tabeli;
- cin >> Wielkosc;
- while(Wielkosc <= 0)
- {
- cout << "Wielkosc Tabeli Jest Niedodatnia. Podaj Wielkosc Tabeli Ponownie: ";
- cin >> Wielkosc;
- }
- int* Tablica = new int[Wielkosc]; //Tworzenie Tabeli; //?;
- for(int i = 0; i < Wielkosc; i++)
- {
- x = rand() % 100 + 1;
- Tablica[i] = x;
- cout << Tablica[i] << " "; //Wyswietlenie Tabeli;
- }
- for(int a = 0; a < Wielkosc; a++)
- {
- if(Tablica[a] > Tablica[a+1])
- {
- c = Tablica[a];
- Tablica[a] = Tablica[a+1];
- Tablica[a+1] = c;
- IloscZmian++;
- }
- if(a == (Wielkosc-1))
- {
- if(IloscZmian == 0)
- {
- break;
- }
- else
- {
- a = -1;
- IloscZmian = 0;
- }
- }
- }
- cout << endl << endl << "PO SORTOWANIU: " << endl;
- for(int y = 0; y < Wielkosc; y++)
- {
- cout << Tablica[y] << " ";
- }
- delete[] Tablica;
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement