Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

istream...

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok here is my code to extract what i need from a file...



ok, now in my assignment i have to do this, but input into a doubly linked

list as i go....

now that isn't too hard, but we have to use a method called input().

here is the constructor for the method input.




now, I think istream& is refering to a pointer in c++.

but in java, would i pass the file instead??

thanks,
Justin
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not the "constructor" for the method: it's the "declaration" for the method. Methods don't have constructors!

The answer to your question is that your Scanner object is the Java equivalent of the C++ istream. An istream is an object that's all set up and opened to read data from, just as a Scanner is. The "&" means you're passing a reference; by default, without that "&", in C++ a copy of the istream object itself would be passed (unlike in Java, where it's always a copy of a reference that is passed.)
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought java didn't support "call-by-reference" parameters...??

anyways... i figured out a way to do what i needed...

but now im stuck..

we have to insert the nodes in order by employee number..

well i was just going to insert, then selectionSort the numbers

afterwards...

but I started to try and switch the values, and i came across 10,

sometimes more to changes to switch the nodes around.

so what im asking is, is there an easier way to get the nodes in order,

without having to find the right spot each time you input a node.

thx,

Justin...

p.s here is my code...



this is the DDLL class...

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i figured out how to arrange the nodes by employee number...

but i dont know how to arrange nodes' .EmpHrs afterwards...

or during...

yeah, i have no clue..

Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the way,

ths is my new, revised code...

the main is the same, but the DDLL class is different..

 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO, you are doing too much in one class. A *more* object oriented design would be to have a number of classes with focused responsibilities. i.e.

  • DoublyLinkedList - responsible for the logic of maintaining a LinkedList of Objects.
  • TextFileReader - responsible for reading lines from a text file
  • Employee - responsible for maintaining information about each Employee (id/ wage/ etc.).
  • EmployeeIDComparator implements Comparator - responsible for implementing the logic about Employee ordering
  • ListSorter - responsible for sorting your DoublyLinkedList on the basis of whatever Comparator you provide it.
  • Your mileage may vary, but by organizing classes in terms of a focused responsibility, your code is more reusable and flexible.
    [ July 05, 2006: Message edited by: Garrett Rowe ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic