Guest User

Untitled

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