Advertisement
Guest User

Untitled

a guest
Nov 9th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <vector>
  2. #include <stdio.h>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. typedef unsigned int ui;
  7.  
  8. double a, b, c, i, j, pivot;
  9. double mediana(double a, double b, double c)
  10. {
  11.   if((c<=a && b>=a) || (c>=a && b<=a) ) return a;
  12.   if((c<=b && a>=b) || (b>=a && b<=c) ) return b;
  13.   return c;
  14. }
  15.  
  16. void swap(double & a, double & b)
  17. {
  18.   double tmp=a;
  19.   a=b;
  20.   b=tmp;
  21. }
  22.  
  23. inline static void mysort(std::vector<double> & array, ui left, ui right)
  24. {
  25.   i=left;
  26.   j=right;
  27.   srand((unsigned)time(NULL));
  28.   a=(rand()%right-left-1)+left;
  29.   b=(rand()%right-left-1)+left;
  30.   c=(rand()%right-left-1)+left;
  31.   pivot=mediana(a, b, c);
  32.  
  33.   while(i<j)
  34.     {
  35.       while(array[i]<pivot)
  36.         i++;
  37.       while(array[j]>pivot)
  38.         j--;
  39.       if(i<=j)
  40.         swap(array[i], array[j]);
  41.       if(left<j) mysort(array, left, j);
  42.       if(i<right) mysort(array, i, right);
  43.     }
  44. }
  45.  
  46. int main()
  47. {
  48.   std::vector<double> nono;
  49.   double tmp;
  50.   for(int i=0;i!=2;i++)
  51.     {
  52.       scanf("%lf", &tmp);
  53.       nono.push_back(tmp);
  54.     }
  55.   mysort(nono, 0, nono.size());
  56.   for(std::vector<double>::iterator it=nono.begin();it!=nono.end();it++)
  57.     printf("%lf", *it);
  58.   return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement