Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. const short SECTOR_MIN = 1; // The lowest sector number
  2. const short SECTOR_MAX = 7; // The max sector number
  3. const short WEIGHT_MIN = 25; // The minimum weight of a pile of trash
  4. const short WEIGHT_MAX = 500; // The max weight of a pile of trash
  5. const short GUILT_MIN = 100; // The min guilt value that a person can have
  6. const short GUILT_MAX = 10000; // The max guilt value a person can have
  7. const short SIZE = 15; // The array sizes
  8.  
  9. struct guilt
  10. {
  11. string name;
  12. short guilt;
  13. };
  14.  
  15. struct trash
  16. {
  17. short sector;
  18. short weight;
  19. };
  20.  
  21. // Description: The bubble_sort() function will sort the values of an
  22. // array from least to greatest.
  23. // Pre: The > operator must be defined.
  24. // Post: The functions will be sorted from greatest to least.
  25.  
  26. template <typename T1, typename T2, typename T3>
  27. void bubble_sort(T1 array[], T2 arr_elem1, T3 arr_elem2, const short SIZE)
  28. {
  29. T2 elem1_temp; // The temporary holding place for array element2
  30. T3 elem2_temp; // The temporary holding place for array element1
  31.  
  32.  
  33. for(int j = 0; j <= SIZE - 1; j++)
  34. {
  35. for(int i = 0; i <= SIZE - 1; i++)
  36. {
  37. if(array[i+1].arr_elem2 > array[i].arr_elem2)
  38. {
  39. elem1_temp = array[i].elem1_temp;
  40. elem2_temp = array[i].elem2_temp;
  41.  
  42. array[i].arr_elem1 = array[i+1].arr_elem1;
  43. array[i].arr_elem2 = array[i+1].arr_elem1;
  44.  
  45. array[i+1].arr_elem1 = elem1_temp;
  46. array[i+1].arr_elem2 = elem2_temp;
  47. }
  48. }
  49. }
  50. }
  51.  
  52.  
  53. // Description: The my_rand() function will put out a random number
  54. // between the lower and upper limit.
  55. // Pre: None
  56. // Post: The function will return a random number.
  57.  
  58. short my_rand(const short lower_lim, const short upper_lim);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement