Wednesday, September 17, 2014

Changes 9/17/14

Java:

  • Chapter 6 starts talking about linked data, and uses the analogy of desks in a classroom, where each desk has the number of the next desk in the sequence on it.
  • This allows the instructor to access any desk in the series, simply by memorizing the number of the first desk, then asking each desk in succession what the number of the next desk is.
  • I decided to test this out in Java, so I wrote a ChainLink class.
  • Each ChainLink has two fields, a data field and a next field.  The data field contains a string, and the next field is initially set to null.
  • The method I wrote to set up the chain is called like this:
  • createChain(new ChainLink("value1"), new ChainLink("value2"), new ChainLink("value3"), new ChainLink("value4"));
  • This takes each ChainLink, and sets the next value of each to the next ChainLink in the sequence.  The ChainLink with datavalue "value4" has its next field set to null, though.
  • Then you can get a ChainLink at whatever index you want, with the getLink() method!
  • Unfortunately I didn't have time to finish the chapter, though.

No comments:

Post a Comment