Guest User

Untitled

a guest
Apr 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class T>
  6.  
  7. void bublesort(T list[], int n)
  8. {
  9.     int i,j;
  10.     T temp;
  11.     for(i=0;i<(n-1);i++)
  12.     for(j=0;j<(n-(i+1));j++)
  13.     if(list[j] > list[j+1])
  14.     {
  15.         temp=list[j];
  16.         list[j]=list[j+1];
  17.     list[j+1]=temp;
  18.     }
  19. }
  20.  
  21. template <class Ts>
  22.  
  23. void printdat(Ts lista[],int n)
  24. {
  25.     int i;
  26.     for(i=0;i<n;i++)
  27.     {
  28.         cout<<lista[i]<<",";
  29.         if(i==n-1)
  30.         cout<<endl;
  31.     }
  32. }
  33.  
  34. int main()
  35. {
  36.     int V1[30]={5,6,3,7,1,5,9,8,4,1,6},n;
  37.     char V2[30];
  38.     double V3[30]={4,5,7,8,4,12,53,64,125,41,52};
  39.     n=11;
  40.     int i;
  41.     for(i=0;i<n;i++)
  42.     {
  43.         cout<<"unesi jedno slovo:";
  44.         cin>>V2[i];
  45.     }
  46.     printdat(V1,n);
  47.     printdat(V2,n);
  48.     printdat(V3,n);
  49.     bublesort(V1,n);
  50.     bublesort(V2,n);
  51.     bublesort(V3,n);
  52.     printdat(V1,n);
  53.     printdat(V2,n);
  54.     printdat(V3,n);
  55.     return 1;
  56. }
Add Comment
Please, Sign In to add comment