DiGraph.h
#pragma once
#include <iterator>
#include <fstream>
#include <memory>
#include <array>
#include <iostream>
#include <stack>
#include <vector>
#include <queue>
class DiGraph
{
private:
class AdjacentcyList
{
private:
class Node
{
public:
std::shared_ptr<Node> next;
int link;
public:
Node(const int& l) :link(l), next(nullptr)
{
}
};
std::shared_ptr<Node> head = nullptr;
public:
class Iterator
{
private:
std::shared_ptr<Node> it;
public:
Iterator(std::shared_ptr<Node> i) :it(i)
{
}
bool operator == (const Iterator& rhs)const
{
return it == rhs.it;
}
bool operator != (const Iterator& rhs)const
{
return !(*this == rhs);
}
const Iterator& operator ++()
{
it = it->next;
return *this;
}
int operator *()const
{
return it->link;
}
};
public:
/**********************************************
函数名称: addNode
函数说明: 为adjacentcyList增加结点
返回值: void
**********************************************/
void addNode(const int& i)
{
if (head == nullptr)
{
head = std::make_shared<Node>(Node(i));
return;
}
std::shared_ptr<Node> curr = head;
while (curr->next != nullptr)
curr = curr->next;
curr->next = std::make_shared<Node>(Node(i));
return;
}
Iterator begin()const
{
return Iterator(head);
}
Iterator end()const
{
return Iterator(nullptr);
}
};
private:
std::unique_ptr<AdjacentcyList[]> adj;
int npoint;
int nedge;
public:
//构造有向图
DiGraph(