Guest User

Untitled

a guest
Jul 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <complex>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8. template <typename tip>
  9. tip *GenerirajNiz(int n)
  10. {
  11. tip *pok(new tip[n]);
  12. for (int i=0; i<n; i++)
  13. {
  14. pok[i]=double(rand())/RAND_MAX;
  15. }
  16. return pok;
  17. }
  18. template <typename tip>
  19. void SortirajRucno(tip *p1, tip *p2)
  20. {
  21. int duzina(p2-p1);
  22. for (int i=0; i<duzina; i++)
  23. {
  24. for (int j=0; j<duzina; j++)
  25. {
  26. if (p1[j]<p1[i])
  27. {
  28. double pomocna=p1[i];
  29. p1[i]=p1[j];
  30. p1[j]=pomocna;
  31. }
  32. }
  33. }
  34. }
  35. bool fkriterija(double a, double b)
  36. {
  37. return a>b;
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43. int n1(5000), n2(5000);
  44. double *niz1, *niz2;
  45. niz1=GenerirajNiz<double>(n1);
  46. niz2=GenerirajNiz<double>(n2);
  47. cout << endl << "Novi niz rucno:" << endl;
  48. SortirajRucno(niz1, niz1+n1);
  49. for (int i=0; i< n1; i++)
  50. {
  51. cout << niz1[i] << endl;
  52. }
  53. sort(niz2, niz2+n2, fkriterija);
  54. cout << endl << "Novi niz(sort);" << endl;
  55. for (int i=0; i<n2; i++)
  56. {
  57. cout << niz2[i] << endl;
  58. }
  59. delete [] niz1;
  60. delete [] niz2;
  61.  
  62. return 0;
  63. }
Add Comment
Please, Sign In to add comment