SUNY Geneseo Department of Computer Science
{Date}
CSci 141, Spring 2005
Prof. Doug Baldwin
Hour exams are graded
Concatenation exercise
List list1
... initialized somehow....
List list2
... initialized somehow ...
List list3 = new List()
list3.concat( list1.copy() )
list3.concat( list2 )
Solution: explicitly make copies (as the code above does -- it started without the "list1.copy()")
Problem: sort a list
(Precondition: all items in the list are comparable using "<", ">")
Solution idea: "bubble sort"
An algorithm based on this idea....
// In a SortableList subclass of List...
sort()
if ( ! this.isEmpty() )
this.findSmallestAndPutAtFront()
//postcondition: smallest item in list is at head
this.getRest().sort()
findSmallestAndPutAtFront()
...
Is it correct?