Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- class MainA{
- private:
- int ile;
- int* tablica;
- public:
- MainA(int=15);//konstruktor
- ~MainA(){delete[] tablica;}//destruktor
- void sortowanie_babelkowe(int[],int);// metoda sortowania babelkowego
- int ZwrocIle(){return ile;} // metoda zwracajaca ile liczb do posortowania
- int* ZwrocTablice(){return tablica;} // metoda zwraca cala tablice
- };
- MainA::MainA(int x){
- ile=x;
- tablica=new int[ile];
- }
- void MainA::sortowanie_babelkowe(int tab[],int n){
- for(int i=0;i<n;i++){
- for(int j=n-1;j>=1;j--){
- if(tab[j]>tab[j-1]){
- int bufor;bufor=tab[j-1];
- tab[j-1]=tab[j];
- tab[j]=bufor;
- }
- }
- }
- }
- int main()
- {
- srand(time(NULL));
- // stworzenie obiektu (obj1)
- MainA obj1;
- // przepisanie losowych liczb do tablicy
- for(int i=0;i<obj1.ZwrocIle();i++){
- obj1.ZwrocTablice()[i]=rand()%100+1;
- }
- // metoda ktora wywoluje sortowanie
- obj1.sortowanie_babelkowe(obj1.ZwrocTablice(),obj1.ZwrocIle());
- // wyswietlenie tablicy
- for(int i=0;i<obj1.ZwrocIle();i++){
- cout << obj1.ZwrocTablice()[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement