please help me topologcal sort
please help i must add topological sort this code but i can't.please help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <queue>
#include <string>
using namespace std;
class City
{
private:
int id;
string name;
public:
City(int id, string name)
{
this->id = id;
this->name = name;
}
int getId()
{
return id;
}
string getName()
{
return name;
}
};
int main()
{
City *cities[10];
cities[0] = new City(1, "Adana");
cities[1] = new City(6, "Ankara");
cities[2] = new City(7, "Antalya");
cities[3] = new City(10, "Balikesir");
cities[4] = new City(16, "Bursa");
cities[5] = new City(26, "Eskisehir");
cities[6] = new City(34, "Istanbul");
cities[7] = new City(35, "Izmir");
cities[8] = new City(45, "Manisa");
cities[9] = new City(61, "Trabzon");
queue<City *> city[10];
city[1].push(cities[2]);
city[2].push(cities[0]);
city[2].push(cities[9]);
city[3].push(cities[6]);
city[4].push(cities[6]);
city[4].push(cities[2]);
city[4].push(cities[5]);
city[5].push(cities[1]);
city[5].push(cities[0]);
city[6].push(cities[5]);
city[6].push(cities[9]);
city[6].push(cities[1]);
city[7].push(cities[3]);
city[7].push(cities[4]);
city[8].push(cities[5]);
city[9].push(cities[1]);
for(int i=0; i<10; i++)
{
while(!city[i].empty())
{
cout<<city[i].front()->getId()<<" ";
city[i].pop();
}
cout<<endl;
}
return 0;
}
|
Topic archived. No new replies allowed.