책에 있던 예제인데요. 에러가.. ㅡㅡ;;
왜 나는 건가요?
밑에 2/3지점 쯤에 // 있는 부분에 봐주세욤.. 부탁드립니다. ^^
#include <iostream.h>
#include <iomanip.h>
#include <process.h>
#include "queue.h"
enum Bool {False, True};
class GraphNode{
friend class Graph;
private:
int vertex;
GraphNode* link;
public:
GraphNode(int v, GraphNode* l=0) : vertex(v), link(l){};
};
class Graph{
private :
int size;
Bool* visited;
GraphNode** graph;
GraphNode** tail;
public :
Graph(int sz);
~Graph();
void ReadGraph(int[][2], int);
void PrintGraph();
void DFS();
void DFS(int);
void BFS(int);
void Components();
};
Graph::Graph(int sz)
{
size=sz;
graph=new GraphNode*[size];
tail=new GraphNode*[size];
for(int i= 0; i<size; ++i)graph[i]=tail[i]=0;
}
Graph::~Graph()
{
GraphNode *p, *q;
for(int i=0; i<size; ++i){
p=graph[i];
q=p->link;
while(1){
if(!p) break;
else{
delete p;
p=q;
if(q) q=q->link;
}
}
}
delete[] graph;
delete[] tail;
}
void Graph::ReadGraph(int edge[][2], int n)
{
int v, w;
GraphNode *nodev, *nodew;
for(int i=0; i<n; ++i){
v=edge[i][0];
w=edge[i][1];
nodev=new GraphNode(v);
nodew=new GraphNode(w);
if(!tail[v])graph[v]=tail[v]=nodew;
elsetail[v]=tail[v]->link=nodew;
if(!tail[w])graph[w]=tail[w]=nodev;
elsetail[w]=tail[w]->link=nodev;
}
}
void Graph::PrintGraph()
{
for(int i=0; i< size; ++i){
cout << setw(3) << i << " -> ";
for(GraphNode *p=graph[i]; p; p=p->link){
cout << p-> vertex;
if(p->link) cout << " -> ";
}
cout << endl;
}
}
void Graph::DFS()
{
visited = new Bool[size];
for(int i=0; i<size; ++i) visited[i] = False;
DFS(0);
delete[] visited;
}
void Graph::DFS(const int v)
{
visited[v] = True;
cout << v << " ";
for(GraphNode *p=graph[v]; p; p=p->link)
if(!visited[p->vertex]) DFS(p->vertex);
}
void Graph::BFS(int v)
{
visited=new Bool[size];
for(int i=0; i<size; i++) visited[i]=False;
visited[v]=True;
Queue<int> q; // 여깁니다. 여기~~ 111 번
q.Insert(v); // 112번줄. 밑에 에러메시지 써놨습니다.
while( !q.IsEmpty() ){
v= q.Delete();
cout << v << " ";
for(GraphNode *p=graph[v]; p; p=p->link)
if( !visited[p->vertex] ){
q.Insert(p->vertex);
visited[p->vertex]=True;
}
}
delete[] visited;
}
void Graph::Components()
{
visited = new Bool[size];
for(int i=0; i<size; i++) visited[i]=False;
for(int i=0; i<size; i++)
if( !visited[i]){
cout << "\n 연결요소 : ";
DFS(i);
}
delete[] visited;
}
void main()
{
int EdgeMat[12][2]={{0,1},{0,2},{1,3},{1,4},{2,5},{2,6},{3,7},{4,7},{5,8},{6,8},{7,9},{8,9}};
int DisConGraph[7][2]={{0,1},{0,3},{1,2},{2,3},{4,5},{4,6},{5,6}};
Graph g(10), c(7);
g.ReadGraph(EdgeMat, 12);
c.ReadGraph(DisConGraph, 7);
cout << "연결그래프 \n";
g.PrintGraph();
cout << "\n깊이 우선 탐색 방문 순서 : ";
g.DFS();
cout << "\n너비 우선 탐색 방문 순서 : ";
g.BFS(0);
cout << "\n\n비연결 그래프 \n";
c.PrintGraph();
c.Components();
}
에러내용입니다.
111: Undefined symbol 'Queue' in function Graph::BFS(int)
111: Expression syntax in function Graph::BFS(int)
112: Undefined symbol 'q' in function Graph::BFS(int)
뭐가 잘못 되었는지 제발좀 가르쳐 주세요.. 감사합니당.
에디트플러스로 작성해서 볼랜드 C++ 컴파일러를 사용했습니당.
|