Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <windows.h>
- #include <time.h>
- using namespace std;
- unsigned long const int n= 200000;
- void bsort(unsigned long int n, float * a)
- {
- unsigned long int l, k;
- float p;
- l = n;
- do
- {
- k = 0;
- l = l - 1;
- for (unsigned long int i = 1; i < 1; i++)
- {
- if (a[i] < a[i + 1])
- {
- if (a[i] > a[i + 1])
- {
- p = a[i]; a[i] = a[i + 1]; a[i + 1] = p; k = k + 1;
- }
- }
- }
- while (k != 0);
- }
- while (k != 0);
- }
- int main()
- {
- float * a = new float[n];
- unsigned long int m;
- int k;
- time_t t;
- clock_t tp,tk;
- double tc;
- srand((unsigned)time(&t));
- do
- {
- cout << "podaj ilość wyrazów ciągu"; cin >> m;
- cout << "ciąg wylosowany" << "\n";
- for (unsigned long int i = 1; i <= m; i++)
- {
- a[i] = rand() % 10000;
- cout<<a[i]<<" \t";
- }
- cout << "\n";
- {
- cout << "metoda bąbelkowa";
- tp = clock();
- bsort(m, a);
- tk = clock(); tc = (tk - tp) / double(CLOCKS_PER_SEC);
- cout << "czas obliczeń= " << tc << " \n";
- }
- cout << "ciąg posortowany" << " \n";
- for (unsigned long int i = 1; i <= m; i++)
- {
- cout << a[i] << "\t";
- }
- cin >> k;
- } while (k != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement