jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Polynomial LinkedList from Text File (Modification) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Polynomial LinkedList from Text File (Modification)" Watch "Polynomial LinkedList from Text File (Modification)" New topic

Polynomial LinkedList from Text File (Modification)

Kayla Keen

Joined: Nov 26, 2011
Posts: 1
I want to modify the below code to read the Polynomial Terms from a text file (vs. hard-coded values)

Furthermore, read data from text file in the format:

P1 = 3 5 1 -1 0 8

P2 = 5 6 2 -1 1 7 0 -4


Name the values P(x) and input the remaining data... Any advice?

Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4627

Welcome to CodeRanch!

Why are you implementing your own linked list? Why don't you just let your Polynomial class consist of a List<Term>, which if you wanted to, you could sort with a Comparator<Term> that ranks terms by their exponents? Or you could even use a TreeMap.

This will get rid of a lot of ugly C-like code (for(Monomial tmp = head; tmp != null; tmp = tmp.next); eww) and you can focus on your problem.

As for your input problem, you could give the Polynomial class a load(InputStream) method, which will scan the stream for pairs of integers until it hits end-of-line, or maybe some other delimiter.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
I agree. Here's the link: http://aspose.com/file-tools
subject: Polynomial LinkedList from Text File (Modification)
It's not a secret anymore!