This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
mcwagner


Newbie


Joined: 02 Sep 2008
Posts: 2

Posted: 02 Sep 2008 03:47:59 pm    Post subject:

I am trying to read in a text file that describes a graph as follows:

1 2 4

1 2 3
4 5 2
2 3
1

Each line corresponds to a node and what nodes are adjacent to it (ex: node zero is adjacent to nodes 1, 2, 4). I want to read the file and using the line that the scanner is on and what integers on that line and place it into an adjacency matrix.

I was attempting to use something like the following:


Code:
Scanner scan = new Scanner(new File(fileName));
scan.useDelimiter( "//r" );
int count = 0;
while(scan.hasNext())
{
     adjacencyMatrix[count][scan.nextInt()] = 1;
}


Anyone have any ideas how to accomplish this?
Back to top
luby
I want to go back to Philmont!!


Calc Guru


Joined: 23 Apr 2006
Posts: 1477

Posted: 03 Sep 2008 07:14:50 am    Post subject:

Why do you have that =1 bit in there. Don't you want the scan.nextInt()? Also, you will want to inc count when going on to the next line.
Back to top
mcwagner


Newbie


Joined: 02 Sep 2008
Posts: 2

Posted: 05 Sep 2008 09:47:12 pm    Post subject:

To clarify:

adjacencyMatrix is a two dimensional array consisting of integers 1 or 0 to indicate that two nodes are connected. The problem is that I'm not sure how to use the delimiter, /r (for a return carry ), as a stopping point to increment count so that it can continue to fill in the matrix...
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement