• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polynomial LinkedList from Text File (Modification)

 
Kayla Keen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5807
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic