YS
Size: a a a
YS
YS
YS
Р
template<class T>
istream& operator >> (istream& in,Graph<T>& A)
{
while(true)
{
A.vertexs.clear();
A.visited.clear();
A.nodes.clear();
int countV;
cout<<"Enter count of vertex\n";
in>>countV;
if (in.fail())
{
cout<<"Введення невірне,спробуйте знову\n";
in.clear();
in.ignore();
continue;
}
A.countVer=countV;
cout<<"Enter vertex\n";
vector<T> vertex;
for(int i=0;i<countV;++i)
{
T a;
in>>a;
vertex.push_back(a);
}
if (in.fail())
{
cout<<"Введення невірне,спробуйте знову\n";
in.clear();
in.ignore(INT_MAX,'\n');
continue;
}
vector<node<T>*> nodes;
vector<bool> visited;
for(int i=0;i<countV;++i)
{
node<T>* tmpNode=new node<T>(vertex[i]);
nodes.push_back(tmpNode);
visited.push_back(false);
}
A.nodes=nodes;
A.visited=visited;
A.vertexs=vertex;
cout<<"Вводьте звязки між ввершинами, якщо захочете припинити ввдення введіть -1\n";
while(true)
{
T a,b;
in>>a;
if(a==-1 or a=='-' or a=="-1") break;
in >> b;
if(b==-1) break;
if(a>=0 && b>=0)
{
if(A.insertEdge(a,b))
{
cout<<"Ребро додано\n";
}else
{
cout<<"Не вірний запис вершин спробуте ще раз\n";
}
}
}
if (in.fail())
{
cout<<"Введення невірне,спробуйте знову\n";
in.clear();
in.ignore();
continue;
}
return in;
}
}
template<class T>
ostream& operator << (ostream& s,const Graph<T>& A)
{
s<<"Кількість вершин= "<<A.countVer<<'\n';
s<<"Список суміжності кожної вершини\n";
for(auto V=A.vertexs.begin();V!=A.vertexs.end();++V)
{
auto indexV=find(A.vertexs.begin(),A.vertexs.end(),*V);
if(*V==A.vertexs[indexV-A.vertexs.begin()])
{
s<<*V<<':';
for(auto it=A.nodes[indexV-A.vertexs.begin()]->adjacencyList.begin();it!=A.nodes[indexV-A.vertexs.begin()]->adjacencyList.end();++it)
{
s<<(*it)<<' ';
}
}
cout<<"\n";
}
return s;
}
RN
Р
RN
RN
Р
Р
Р
Р
RN
Р
Р
RN
RN
RN