Hi,
I have some vertices and edges and i have to create an adjacency list. I have taken an array and stored all vertices in the array. Now i need to add the edges to the graph. The input is given as a text file. When i read "a b 5"--> thats the edge between vertex 'a' and 'b' and has a weight 5. I dont know how to link it..... means when i read 'a' it should go to the index where i have stored 'a' and create a link to 'b'. Again if there is an edge from "a-->c" then the predecessor of node 'c' should be 'b'. Example: a-->b-->c-->/(null).
i am pasting the code that i have done till now
public void readInput()
{
Scanner input = null;
try
{
input = new Scanner(new FileInputStream("Test1.txt"));
StringTokenizer st = new StringTokenizer("Test1.txt");
String [] array = new String[10];
String vertex = input.next();
System.out.println("# of Vertexs are "+vertex);
for(int i=0;i<4;i++)
{
// while(input.hasNextLine())
array[i]=input.next();
System.out.println("Vertex " +array[i]);
}
String edges = input.next();
System.out.println("edges" +edges);
}
catch(FileNotFoundException e)
{
System.out.println("The file couldnt be found");
System.exit(0);
}
catch(IOException e)
{
System.out.println("Error reading from file");
System.exit(0);
}
}