Solutions for those exercises.
Multiple Choices
-
Put a checkmark in the box corresponding to true statements about the List abstract data type.
- A list contains an finite collection of elements, in a particular order.
- A list cannot contain multiple elements with the same value.
- A list must have a fixed number of elements.
- A list is generally endowed with an operation to test for emptiness.
- Only the element at the beginning of a list can be removed.
Exercises
-
Given the usual implementation of
Cell
andCList
:public class CList<T>{ private Cell first; private class Cell{ public T Data { get; set; } public Cell Next { get; set; } public Cell(T dataP, Cell nextP){Data = dataP; Next = nextP;} } public CList(){first = null;} }
Write…
-
… a
IsEmpty
property that istrue
if theCList
calling object is empty. -
… the
AddF
method that add a cell at the beginning of the CList (to the left). -
… a series of statements, to be inserted in a
Main
method, that a. create aCList
object capable of containingchar
, b. insert the elements'b'
and'/'
in it, c. displays whether it is empty usingIsEmpty
.
-
-
Briefly explain the purpose of the
IsReadonly
property from theICollection<T>
interface, and list at least two methods in a List implementation realizingICollection<T>
that should use it. -
Explain the main differences between singly linked list and doubly linked list, and name a few methods that need to be implemented differently.
-
For what operation(s) does doubly linked list provide a complexity gain over singly linked list?