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.
You must use the given parts of the program without changing
them. For example, all memory management must be done using
the given procedures get...memory
and
return...memory
- do not directly use C's built-in
procedures malloc
and free
.
Note that the main program writes out information about how much memory has been allocated by your procedures but not returned to the global pool. These numbers should always be 0: if they are not, you have bugs to fix.
delete(collection c, collection_element e)
so that it
meets the specification given in class. The procedure must be linear
time, i.e. its execution time should be proportional to the size
of the collection c
. This means you are permitted to loop
through the elements of c
one at a time.
This procedure is tricky enough that it needs to be carefully
designed before you begin writing code. For example, when you delete a
node, say N, it is necessary to update the next
pointer
of the node preceding N in the list. In order to do the update, you
will need a pointer to that node: N itself does not contain a pointer
to the node that precedes it, so your algorithm for deleting a node
will include a method for getting a pointer to the node preceding the
one to be deleted. Try to do this as efficiently as you can. As
suggested in the lecture, node-and-arc diagrams will be very helpful
for designing this procedure.
separate
having four arguments:
separate
must use the map
procedure, and it
must not depend on the implementation details of
`collections' - all its processing of collections must be done by
using the operations in the specification of `collection'.
In the model solution, the implementation of separate
is 4 lines of code excluding declarations, and uses an auxiliary
function (1 line of code).
typedef int collection_element; typedef struct collection_node { collection_element value; struct collection_node * next; } collection_node; typedef struct { int size; collection_node *first,*last; } collection_header; typedef collection_header *collection;