Sunday, December 7, 2008

201 preliminary on final project

This week we will be talking about an abstract data type called list. In its simplest form, a list is just an everyday list of items, for example, a to-do list written on the back of an envelope: you can add something to it, cross something off, read the whole thing, count how many things you have to do, etc.

We will have a list of integers kept in ascending order. If you want to start thinking about it now, you can write a program that keeps the contents of a small array in order. Write a loop that [1] either gets a new integer from the user or generates a random integer, [2] puts the new integer in its correct place in the list, [3] then displays the current contents of the list. You'll need a way to get out of the loop, too. That's enough for now.

On Tuesday, we will talk about other methods that every list contains, such as delete an item, find out whether the list contains X, report its size, etc. You can look at the List API in the Java docs for some ideas of typical list methods.

However! Note that your program will not include objects that are already part of Java: you will write all of the code that creates and maintains the list. And your program will keep the list in order with every new entry. Since it's never out of order, there will be no sorting.

No comments: