fork download
  1. #include <iostream>
  2. using namespace std;
  3. void get_array(int*,int);
  4. void bubble_sort(int*,int);
  5. int main(void) {
  6. // your code goes here
  7.  
  8. int size;
  9. int* ptr;
  10. cin>>size;
  11. get_array(ptr,size);
  12. bubble_sort(ptr,size);
  13. for(int i=0;i<size;i++)
  14. {
  15. cout<<ptr[i]<<" ";
  16. }
  17. return 0;
  18. }
  19. void get_array(int* A,int n)
  20. {
  21. int i;
  22. for(i=0;i<n;i++)
  23. {
  24. cin>>A[i];
  25. }
  26. }
  27. void bubble_sort(int* A,int n)
  28. {
  29. int i,j,t;
  30. for(j = 1;j<n;j++)
  31. {
  32. for(i=0;i<n-j;i++)
  33. {
  34. if(A[i]>A[i+1])
  35. {
  36. t = A[i];
  37. A[i] = A[i+1];
  38. A[i+1] = t;
  39. }
  40. }
  41. }
  42. }
Runtime error #stdin #stdout 0s 4384KB
stdin
5
1 3 2 5 4
stdout
Standard output is empty