Using Smalltalk, assume input will be acceptable. For example, finding the next
ID: 3633820 • Letter: U
Question
Using Smalltalk, assume input will be acceptable. For example, finding the next to last element in a list will not be tested with a one element, or empty list.
The class OrderedCollection is a collection class with a fixed order but indefinite size. Use the browser to familiarize yourself with the methods of this class.
Then subclass this class, naming it YourNameCollection and add the following method to your class
f. Merge two (ascending) ordered lists of integers into a single (ascending) sorted collection. Call it merge. For example: sortedC merge: anothersortedC
p := OrderedCollection new.
p addAll: #(1 2 12).
p merge: ( OrderedCollection new addAll #(3 4 5 8).
p.
=> OrderedCollection(1 2 3 4 5 8 12)
Explanation / Answer
Dear, Here is the code YourNameCollection extend [ init [ count=0. numbers := OrderedCollection new. numbers add: 1; add: 2; add: 3; add: 4; add: 5; add: 6; add: 7; numbers do: [ :each | each element modulo of element/2 is 0 ifTrue: [ count=count+1]] ] ]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.