📄 lbase.h
字号:
// file lbase.h
// initial linked base for linked graph representations
#ifndef LinkedBase_
#define LinkedBase_
#include <iostream.h>
#include <stdlib.h>
#include "network.h"
#include "chain.h"
#include "xcept.h"
template <class T> class LinkedWDigraph;
template <class T> class LinkedWGraph;
template<class T>
class LinkedBase : public Network
{
friend class LinkedDigraph;
friend class LinkedGraph;
friend LinkedWDigraph<int>;
friend LinkedWGraph<int>;
public:
LinkedBase(int Vertices = 10)
{
n = Vertices;
e = 0;
h = new Chain<T> [n+1];
}
~LinkedBase()
{
delete [] h;
}
int Edges() const
{
return e;
}
int Vertices() const
{
return n;
}
int OutDegree(int i) const
{
if (i < 1 || i > n)
throw OutOfBounds();
return h[i].Length();
}
void Output() const
{
Output(cout);
}
void Output(ostream& out) const;
void InitializePos()
{
pos = new ChainIterator<T> [n+1];
}
void DeactivatePos()
{
delete [] pos;
pos = NULL;
}
private:
ChainIterator<T> *pos;
int n; // number of vertices
int e; // number of edges
Chain<T> *h; // adjacency list array
};
template<class T>
void LinkedBase<T>::Output(ostream& out) const
{// Output the adjacency lists.
for (int i = 1; i <= n; i++)
{
out << "Vertex " << i << " = ";
h[i].Output(out);
out << endl;
}
}
// overload <<
template <class T>
ostream& operator<<(ostream& out, const LinkedBase<T>& x)
{
x.Output(out);
return out;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -