• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Polynomial LinkedList from Text File (Modification)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic