Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <stdio.h>
- #include <cstdlib>
- #include <ctime>
- typedef unsigned int ui;
- double a, b, c, i, j, pivot;
- double mediana(double a, double b, double c)
- {
- if((c<=a && b>=a) || (c>=a && b<=a) ) return a;
- if((c<=b && a>=b) || (b>=a && b<=c) ) return b;
- return c;
- }
- void swap(double & a, double & b)
- {
- double tmp=a;
- a=b;
- b=tmp;
- }
- inline static void mysort(std::vector<double> & array, ui left, ui right)
- {
- i=left;
- j=right;
- srand((unsigned)time(NULL));
- a=(rand()%right-left-1)+left;
- b=(rand()%right-left-1)+left;
- c=(rand()%right-left-1)+left;
- pivot=mediana(a, b, c);
- while(i<j)
- {
- while(array[i]<pivot)
- i++;
- while(array[j]>pivot)
- j--;
- if(i<=j)
- swap(array[i], array[j]);
- if(left<j) mysort(array, left, j);
- if(i<right) mysort(array, i, right);
- }
- }
- int main()
- {
- std::vector<double> nono;
- double tmp;
- for(int i=0;i!=2;i++)
- {
- scanf("%lf", &tmp);
- nono.push_back(tmp);
- }
- mysort(nono, 0, nono.size());
- for(std::vector<double>::iterator it=nono.begin();it!=nono.end();it++)
- printf("%lf", *it);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement