Due date:
Late assignments will be penalized 10% per day, and will not be accepted after .
Name, Student Number, Assignment Number, Course Number (T26)
Assignments which are not in an envelope will not be marked
Deposit your envelope in .
Your program must conform to the programming standards. These are described in a separate sheet.
foo
- you are expected to devise
a recursive algorithm and code foo
to use this
algorithm. Typically, you'll two choices:
foo
so that it calls itself
recursively.
foo
so that it calls an auxiliary
function, say foo_aux
, that is recursive and does
all the interesting work. You might choose this option when the
initial values for the recursive algorithm are not identical to
foo
's initial parameters; or, more generally, when
initializations are required before starting the algorithm, or
when you need to clean up after it finishes.
For questions 3 and 4, you will be given the binary, not
the source, for an implementation of four list operations:
is_empty
, head
, tail
, and
read_list
specified below. You can link these into your
program, but there is no way for you to know how lists are
implemented. The specification tells you all you need to know to use
these operations.
is_empty
head
tail
read_list
addup
function described in class with these arguments:
addup(0,9,X)
.
addup(0,9,X)
?
copy
(S,Scopy) that
makes a copy of the given stack S. copy
must leave S
unchanged - to verify this, write a function called
copy_test
that reads in S, calls copy
, and
then prints out S and Scopy.
Use the main program you are given exactly as it is (it calls
copy_test
).
head
and tail
functions provided,
write a recursive function smallest
(L) that
returns the smallest integer in the given list, L. You may assume L is
not empty.
nth
(N,L),
where N is an integer, L a list. If L contains N (or more) elements,
then the function returns the Nth one from the beginning (the first
element is L's head). If L contains fewer than N elements, the
function returns the last element in L.