Due May 20, at the beginning of class, submitted as described below for each problem. The purpose of this assignment is to have you compare Smalltalk and Java style iteration, and to investigate the 'block' construct in Smalltalk.
The do: method supports Smalltalk-style iteration. In standard Smalltalk style, this would be all you would need. However, for the purposes of this assignment, also define the iterator method as described above, which should return a list iterator object to support Java-style iteration. The iterator should be an instance of a class ListIterator, and should include next and hasNext methods (just as with the Java Iterator interface). You do not need to deal with the case of a list that is modified while there is an iterator active on it.
For computer submission of your code, select the class category 341-assignment6 in a browser, and then pick 'fileOut' from the right-button menu. Then for the paper version, pick 'printOut'. (The 'printOut' option creates an HTML file which has nicer formatting. Unfortunately it isn't set up to file in correctly, however.)
Testing. Test your linked list by making an instance of it, and demonstrating it in operation, using both the Smalltalk and Java style iteration, as well as the other methods specified above. For Java style iteration, demonstrate that you can have two iterators at the same time, functioning independently.
You may want to initially run these tests in a workspace, but before submitting your homework, put the test cases and a copy of the transcript and other results in a file. To create this file for the electronic submission for your answer to this question, select the "open..." menu item, then "file list", then "add new file" in the upper-right-hand pane of the file list. This file will be used just like a workspace, except that you can save the contents. This testing output file should be submitted both via computer and on paper.
| c | c := SortedCollection sortBlock: [...]. c add: 'm'. c add: 'peach'. c add: 'apple'. c add: 'watermelon'. c add: 'cantaloupe'. c do: [:s | Transcript show: s. Transcript cr].where you should replace the block [...] with some suitable code to sort the strings as described above.
For submission, save your completed version of the code above and output together in one file rather than a workspace, as described above for Problem 1, and submit the file via computer and on paper.
Here is the class:
Object subclass: #BlockTester instanceVariableNames: 'assignBlock accessBlock' classVariableNames: '' poolDictionaries: '' category: '341 stuff' createBlocks | temp | assignBlock := [:k | temp := k+100]. accessBlock := [temp+5] set: x assignBlock value: x get ^accessBlock valueNow put the class through its paces:
| bt | bt := BlockTester new. bt createBlocks. bt set: 100. bt getFor this part, submit answers to the following questions on paper only: