// ConsoleApplication4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int length = 5;
int i, j, k;
int arr_from[length] = { 1, 3, 0, 0, 2 };
int arr_to[length] = { 2, 2, 1, 3, 0 };
int res_from[length] = { 0 };
int res_to[length] = { 0 };
vector<int> head(0,0);
vector<int> body(0,0);
cout << "Graph:" << endl;
for (i = 0; i < length; ++i)
{
cout << arr_from[i] << " -> " << arr_to[i] << endl;
}
cout << endl;
for (i = 0; i < length; ++i)
{
for (j = k = 0; j < length; ++j)
if (arr_from[j] < arr_from[i] || (arr_from[i] == arr_from[j] && i < j)) k++;
res_from[k] = arr_from[i];
res_to[k] = arr_to[i];
}
cout << endl;
cout << "Sorted:" << endl;
for (i = 0; i < length; ++i)
{
cout << res_from[i] << " -> " << res_to[i] << endl;
}
cout << endl;
int tmp;
k = 0;
for (i = 0; i < length; ++i)
{
if (res_from[i] == res_from[i + 1])
{
head.push_back(res_to[i]);
body.push_back(res_to[i + 1]);
}
else
{
for (j = 0; j < length; ++j)
{
if (i == res_from[j])
{
head[k] = res_to[j];
body[k] = -1;
}
}
}
k++;
}
cout << endl;
cout << "List: " << endl;
for (i = 0; i < length; ++i)
{
cout << head[i] << " -> " << body[i] << endl;
}
return 0;
}