Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int PathCost[12][3] = {
- { 1, 2, 17 },
- { 2, 3, 6 },
- { 3, 4, 11 },
- { 4, 5, 19 },
- { 5, 6, 9 },
- { 1, 5, 20 },
- { 1, 6, 4 },
- { 1, 7, 24 },
- { 2, 7, 12 },
- { 2, 4, 8 },
- { 4, 7, 15 },
- { 5, 7, 32 },
- };
- void change(int *a,int*b)
- {
- int temp[3];
- for (int i = 0; i < 3; i++)
- {
- temp[i] = a[i];
- a[i] = b[i];
- b[i] = temp[i];
- }
- }
- void costsort()
- {
- for (int i = 0; i < 12; i++)
- {
- for (int j = 0; j < 12 - i - 1; j++)
- {
- if (PathCost[j][2]>PathCost[j + 1][2])
- change(PathCost[j], PathCost[j + 1]);
- }
- }
- cout << "costsort:" << endl;
- for (int i = 0; i < 12; i++)
- {
- for (int j = 0; j < 3; j++)
- cout <<"\t"<< PathCost[i][j] ;
- cout << endl;
- }
- }
- void main()
- {
- costsort();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement