Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <complex>
- #include <cstdlib>
- using namespace std;
- template <typename tip>
- tip *GenerirajNiz(int n)
- {
- tip *pok(new tip[n]);
- for (int i=0; i<n; i++)
- {
- pok[i]=double(rand())/RAND_MAX;
- }
- return pok;
- }
- template <typename tip>
- void SortirajRucno(tip *p1, tip *p2)
- {
- int duzina(p2-p1);
- for (int i=0; i<duzina; i++)
- {
- for (int j=0; j<duzina; j++)
- {
- if (p1[j]<p1[i])
- {
- double pomocna=p1[i];
- p1[i]=p1[j];
- p1[j]=pomocna;
- }
- }
- }
- }
- bool fkriterija(double a, double b)
- {
- return a>b;
- }
- int main()
- {
- int n1(5000), n2(5000);
- double *niz1, *niz2;
- niz1=GenerirajNiz<double>(n1);
- niz2=GenerirajNiz<double>(n2);
- cout << endl << "Novi niz rucno:" << endl;
- SortirajRucno(niz1, niz1+n1);
- for (int i=0; i< n1; i++)
- {
- cout << niz1[i] << endl;
- }
- sort(niz2, niz2+n2, fkriterija);
- cout << endl << "Novi niz(sort);" << endl;
- for (int i=0; i<n2; i++)
- {
- cout << niz2[i] << endl;
- }
- delete [] niz1;
- delete [] niz2;
- return 0;
- }
Add Comment
Please, Sign In to add comment