Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
Servermaster Servermaster is offline
Member Aktif
 
Join Date: Nov 2011
Posts: 257
Rep Power: 14
Servermaster mempunyai hidup yang Normal
Default [help] BFS 2 errors

misi agan2 yg baik hati,



super duper newbie mau nanya lagi nih...



*tentang BFS. hampir nyerahhh

gimana sih memperbaiki 2 error ini:




Code:

#include
#include
#include
#include
#include
using namespace std;

const int INFINITY = 999999999;
enum Color { WHITE, GRAY, BLACK };

class Vertex
{
public:
Vertex();
Vertex(char id);
~Vertex();
char Vertex::getId() const;
void Vertex::setId(char arg);

bool operator color;
color[r] = WHITE;
color[s] = WHITE;
color[t] = WHITE;
color[u] = WHITE;
color[v] = WHITE;
color[w] = WHITE;
color[x] = WHITE;
color[y] = WHITE;
map< Vertex , int> distance;
distance[r] = INFINITY;
distance[s] = INFINITY;
distance[t] = INFINITY;
distance[u] = INFINITY;
distance[v] = INFINITY;
distance[w] = INFINITY;
distance[x] = INFINITY;
distance[y] = INFINITY;
map< Vertex , char> parent;
parent[r] = '0';
parent[s] = '0';
parent[t] = '0';
parent[u] = '0';
parent[v] = '0';
parent[w] = '0';
parent[x] = '0';
parent[y] = '0';

//create the adj lists
list adj_r;
list adj_s;
list adj_t;
list adj_u;
list adj_v;
list adj_w;
list adj_x;
list adj_y;
adj_r.push_back(s);
adj_r.push_back(v);
adj_s.push_back(r);
adj_s.push_back(w);
adj_t.push_back(w);
adj_t.push_back(x);
adj_t.push_back(u);
adj_u.push_back(t);
adj_u.push_back(x);
adj_u.push_back(y);
adj_v.push_back(r);
adj_w.push_back(s);
adj_w.push_back(t);
adj_w.push_back(x);
adj_x.push_back(w);
adj_x.push_back(t);
adj_x.push_back(y);
adj_x.push_back(u);
adj_y.push_back(x);
adj_y.push_back(u);

//map vertices to corresponding lists
map< Vertex , list > adj;
adj[r] = adj_r;
adj[s] = adj_s;
adj[t] = adj_t;
adj[u] = adj_u;
adj[v] = adj_v;
adj[w] = adj_w;
adj[x] = adj_x;
adj[y] = adj_y;

//other objects
queue q;
Vertex currentVertex;
Vertex currentDecescendant;

//start algorithm
color[s] = GRAY;
distance[s] = 0;
parent[s] = NULL;
q.push(s);

//in while loop
while( !q.empty() )
{
//dequeue
currentVertex = q.front();
q.pop();

//for each currentDecescendant in adj[currentVertex]
list::iterator it;
for (it = adj[currentVertex].begin(); it != adj[currentVertex].end(); it++)
{
currentDecescendant.setId(it->getId());
if (color[currentDecescendant]==WHITE)
{
color[currentDecescendant] = GRAY;
distance[currentDecescendant] = distance[currentVertex] + 1;
parent[currentDecescendant] = currentVertex.getId();
q.push(currentDecescendant);
}
}
color[currentVertex] = BLACK;
}
cout

Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 12:16 AM.


no new posts