Question
Given the following list structure: template class Link { public: Elem element; // Value for this node Link *next; // Pointer to next node };
Given the following list structure:
template
public:
Elem element; // Value for this node
Link *next; // Pointer to next node
};
template
class LList : public List
private:
Link
Link
Link
bool insert(const Elem& item) {
fence->next = new Link
if (tail == fence) tail = fence->next;
return true;
}
void print() const {
Link
cout
while (temp != fence) {
cout next->element
temp = temp->next;
}
cout
while (temp->next != NULL) {
cout next->element
temp = temp->next;
}
cout
}
}
Given that score is a variable of List and its values are:
a)
What is the output of score.print()?
(5 marks)
b)
Draw the linked list including the head, fence and tail pointers after executing
score.insert(2).
(5 marks)
c)
Assume Elem and Link cost 32 and 8 bytes. Calculate the overhead fraction for the singly
linked list.
(3 marks)
d)
List one advantage and one disadvantage of singly list comparing with array-based list?
(4 marks)
[17 marks) Given the following list structure: template
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started