Advertisement
Guest User

Untitled

a guest
Apr 24th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cassert>
  3.  
  4. int max( int a , int b )
  5. {
  6. if( a>b ) return a;
  7. else return b;
  8.  
  9. assert(1);
  10. }
  11.  
  12. void testMax()
  13. {
  14. assert( max(3,9)==9 );
  15. assert( max(9,3)==3 );
  16. }
  17.  
  18. void swap( int *a , int *b )
  19. {
  20. int temp = *a;
  21. *a = *b;
  22. *b = temp;
  23. }
  24.  
  25. void testSwap()
  26. {
  27. int a=8,b=2;
  28. swap(&a,&b);
  29. assert(a==2);
  30. assert(b==8);
  31. }
  32.  
  33. void sort( int array[] , int size )
  34. {
  35. for( int i = 0 ; i < size-1 ; ++i )
  36. for( int j = i+1 ; j < size ; ++j )
  37. if( array[i] > array[j] )
  38. {
  39. int temp = array[i];
  40. array[i] = array[j];
  41. array[j] = temp;
  42. }
  43. }
  44.  
  45. void testSort()
  46. {
  47. int arr[4] = {9,7,5,3};
  48. int result[4] = {3,5,7,9};
  49. sort(arr,4);
  50. for( int i = 0 ; i < 4 ; ++i )
  51. assert( arr[i] == result[i] );
  52. }
  53.  
  54. int main()
  55. {
  56. testMax();
  57. testSwap();
  58. testSort();
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement