These questions use the following type Cell.
struct Cell
{
Cell* next;
int item;
Cell(int i, Cell* n)
{
item = i;
next = n;
}
};
Write a statement that will create variable L, of type Cell*, and make it point to new linked list holding only one value, 30.
Which of the following will create variable L and make it point to a new linked list holding 1 and 2, in that order?
Suppose that L is a variable of type Cell* that has already been created and t is a variable of type int. Linked list L has at least two numbers in it. Which of the following sets variable t to the second integer in list L?
Which of the following sequences of statements correctly removes the first cell of a linked list L, making L point to the rest of the list, and deletes the removed cell?
Write a C++ definition of function addToFront(x,L) which
returns the list that you get by adding number x to the
front of list L.
Cell* addToFront(int x, Cell* L)
Write a C++ definition of function isSingleton(L) that
returns true if L is a singleton list, and false otherwise.
(A singleton list has exactly one number in it.)
bool isSingleton(const Cell* L)
Write a C++ definition of
function firstPositive(L) that returns the first positive
number in linked list L. If L does not contain a
positive number, then firstPositive(L) should return 0.
Remember that L is a linked list, not an array.
int firstPositive(const Cell* L)
Write a C++ definition of function isSorted(L), which
returns true if L is in strictly ascending order and returns false if
L is not in ascending order. The empty list is considered to
be in ascending order.
bool isSorted(const Cell* L)
Explain why the following is not a correct definition
of function tail, which returns the result of removing
the first member of linked list L.
Cell* tail(Cell* L)
{
Cell* p = L;
Cell* answer = p->next;
delete p;
return answer;
}
Explain why the following is not a correct definition of
function addToFront, from a previous exercise.
Cell* addToFront(int x, Cell* L)
{
Cell c;
c.item = x;
c.next = L;
return &c;
}