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.
-
Implementing a list as a doubly linked list (as opposed to singly linked list) allows to …
- use fewer attributes.
- keep track of the end of the list.
- store more elements.
- insert at the beginning of the list faster.
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. -
… a
AddF
method that takes an argument of typeT
and adds it at the beginning (“to the left”) of theCList
calling object. -
… a
RemoveL
method that remove the value at the end (“to the right”) of theCList
calling object and returns it. -
… 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
. -
If the
AddF
andRemoveL
were the only two methods to add to and to remove from the list, what would be the name of the data-structure we actually just implemented?
-
-
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?