/*
点类
*/
#ifndef NODE_H__
#define NODE_H__
#include "arc.h"
#include <memory>
#include <string>
struct node
{
std::string node_name;
std::shared_ptr<arc> arc;
node()
{
node_name.clear();
arc.reset();
}
node(const std::string name)
{
node_name=name;
arc.reset();
}
};
#endif
/**
边类
**/
#ifndef ARC_H__
#define ARC_H__
#include <memory>
#include <string>
struct arc
{
std::shared_ptr<arc> next;
std::string node_name;
arc(const std::string& name)
{
next.reset();
node_name=name;
}
arc()
{
node_name.clear();
next.reset();
}
};
#endif
/**
一个邻接表表示的有向图
**/
#ifndef GRAPH_H__
#define GRAPH_H__
#include <vector>
#include <string>
#include <algorithm>
#include <memory>
#include <map>
#include <iostream>
#include "node.h"
#include "arc.h"
class graph
{
private:
typedef std::vector<std::shared_ptr<node> >::iterator iterator;
std::shared_ptr<arc> null_arc;
public:
graph()
{
null_arc.reset();
}
bool add_node(const std::string& name)
{
auto index=vec.begin();
for(;index!=vec.end();++index)
{
if((*index)->node_name==name)
break;
}
if(index!=vec.end())
return false;
vec.push_back(std::shared_ptr<node>(new node(name)));