Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include<time.h>
- void wybieranie(int a[], int n)
- {
- int k, x;
- int ilosc = 0;
- for (int i = 0; i < n - 1; i++)
- {
- k = i;
- x = a[i];
- for (int j = i + 1; j < n; j++)
- if (a[j] < x)
- {
- k = j;
- x = a[j];
- }
- ilosc++;
- a[k] = a[i];
- a[i] = x;
- }
- std::cout << "[Wybieranie] Ilosc porownian " << ilosc << std::endl;
- }
- void wstawianie(int a[], int n)
- {
- int j, x;
- int ilosc = 0;
- int ilosc_while = 0;
- int i = 0;
- for (i = 1; i < n; i++)
- {
- x = a[i];
- j = i - 1;
- while (j >= 0 && x < a[j])
- {
- a[j + 1] = a[j];
- j--;
- ilosc_while++;
- }
- a[j + 1] = x;
- ilosc++;
- }
- double l = (1 / i) + 1;
- std::cout << "[Wstawienie]LSR :" << l << std::endl;
- std::cout << "[Wstawienie]N = :" << ilosc << std::endl;
- std::cout << "[Wstawienie]Ilosc porownian w petli while " <<ilosc_while << std::endl;
- }
- int main()
- {
- int tab[1000];
- srand(time(0));
- for (int i = 0; i < 1000; i++)
- tab[i] = rand();
- int j = 0;
- int k = 0;
- long n = 1000;
- wybieranie(tab, n);
- wstawianie(tab, n);
- int pes = ((n - 1) * n) / 2;
- std::cout << "Pesymistyczna " << pes << std::endl;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement