File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Polynomial LinkedList from Text File (Modification)

Kayla Keen
Greenhorn

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

etc...

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


Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3596
    
  14

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.
 
Consider Paul's rocket mass heater.
 
subject: Polynomial LinkedList from Text File (Modification)
 
Similar Threads
Help required to read binary file
Current Object confusion
what's wrong with my program about JNI callback
Bezier Curve
graph plotting