Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- void swap(int *xp, int *yp)
- {
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- void bubbleSort(int arr[], int n)
- {
- int i, j;
- for (i = 0; i < n-1; i++)
- for (j = 0; j < n-i-1; j++)
- if (arr[j] > arr[j+1])
- swap(&arr[j], &arr[j+1]);
- }
- void printArray(int arr[], int size)
- {
- int i;
- for (i=0; i < size; i++)
- printf("%d ", arr[i]);
- }
- int main()
- {
- int a;
- a=0;
- while( a < 9)
- {
- cout << rand() << endl;
- a++;
- }
- system("PAUSE");
- double roznica;
- cout.setf(ios::fixed); //notacja zwykla, czyli nie wywali wyniku typu 1.175000e+003
- cout.precision(5); //liczba miejsc po przecinku, dokladnosc naszego wyniku
- clock_t start, koniec; //inicjacja zmiennych zegarowych
- start=clock(); //zapisanie czasu startu mierzenia
- int arr[] = { rand(), rand(), rand(), rand(),rand(), rand(), rand(), rand(),rand(), rand(), rand(), rand(),rand(), rand(), rand(), rand(),rand(), rand(), rand(), rand(),rand(), rand(), rand(), rand() };
- int n = sizeof(arr)/sizeof(arr[0]);
- bubbleSort(arr, n);
- printf("Posortowane liczby to: ");
- printArray(arr,n );
- koniec=clock();//zapisanie konca mierzenia
- roznica=(koniec-start)/(double)CLOCKS_PER_SEC;//obliczenie roznicy, czyli czasu wykonania
- cout<<"\n \n \n Czas wykonania: "<<roznica<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement