Advertisement
wendy890711

191220 pathcost排大小

Dec 20th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int PathCost[12][3] = {
  6. { 1, 2, 17 },
  7. { 2, 3, 6 },
  8. { 3, 4, 11 },
  9. { 4, 5, 19 },
  10. { 5, 6, 9 },
  11. { 1, 5, 20 },
  12. { 1, 6, 4 },
  13. { 1, 7, 24 },
  14. { 2, 7, 12 },
  15. { 2, 4, 8 },
  16. { 4, 7, 15 },
  17. { 5, 7, 32 },
  18.  
  19. };
  20.  
  21. void change(int *a,int*b)
  22. {
  23. int temp[3];
  24. for (int i = 0; i < 3; i++)
  25. {
  26. temp[i] = a[i];
  27. a[i] = b[i];
  28. b[i] = temp[i];
  29. }
  30. }
  31.  
  32. void costsort()
  33. {
  34. for (int i = 0; i < 12; i++)
  35. {
  36. for (int j = 0; j < 12 - i - 1; j++)
  37. {
  38. if (PathCost[j][2]>PathCost[j + 1][2])
  39. change(PathCost[j], PathCost[j + 1]);
  40. }
  41. }
  42.  
  43. cout << "costsort:" << endl;
  44. for (int i = 0; i < 12; i++)
  45. {
  46. for (int j = 0; j < 3; j++)
  47. cout <<"\t"<< PathCost[i][j] ;
  48. cout << endl;
  49. }
  50. }
  51.  
  52. void main()
  53. {
  54. costsort();
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement