Graph related problem.

I have a dictionary text file being input into a graph. The program asks the user how many letters they want to use, then there is a conditional statement, the code only inputs words (vertices) that are x letters long.

Exmaple: if they put 3, the vertices in the graph will be "ban", "bet", "bit"....etc;

1
2
3
4
5
6
7
8
9
10
11
12
while(text.good())
	{
	getline(text,line);
	if(line.length() == x)
	{
	
		G.addVertex(line);
		
	}
	

	}

however, now i need to add edges between words that are ONLY 1 character different.

Example: "bat" and "Cat" "dig" and "dug". i need to do that with every vertex in the graph.



Any idea how to do this? I have some code that implements some basic graph functions, like moving, adding vertices, edges, showing edges, and even comparing two strings and getting their number of differences. so if you need to see any of that, i can include it. but i just need a general direction on what to do with this or even how to.
Last edited on
At least show some effort
1
2
3
4
traverse(G, a)
   traverse(G,b)
      if( diff(a,b)==1 )
         G.add_edge(a,b)


By the way, while( getline(text, line) )
lol ouch. Someone woke up on the wrong side of the bed today I guess. I've been working on this code for a while already but I ran into a wall with this part of the program. I'm a newbie at coding, but no one would answer my question in Beginners so i asked it here. But THAAAANKS. I guess. I didn't ask you to write the code for me either, I asked HOW to do it. You could've just said traversal lol.
¡¿You couldn't think of traversal?!
I was hoping for you to complain on a O(N^2) solution.
http://en.wikipedia.org/wiki/Graph_%28abstract_data_type%29

Adjacency lists are preffered if you want to add an edge.
Topic archived. No new replies allowed.