Question: This question is about the linked list classes SLLNode and SLList discussed in lectures last week. ( a ) Consider the following specification for a
This question is about the linked list classes SLLNode and SLList discussed
in lectures last week.
a Consider the following specification for a program deleteLast inside
of the class SLList.
void deleteLast
Postcondition: Removes the very last node from the list,
if it exists, leaving all other nodes in the list.
Given the following "before execution" diagrams, sketch the corre
sponding "after execution" diagrams, ie assuming the three initial
configurations for the input list, what are the corresponding config
b Now fill in the gaps indicated by to complete the implementation
of deleteLast.
void deleteLast
if head null The list has no nodes
if headnextnull The list has one node
head
else The list has at least two nodes
SLLNode temp search for the next but last node....
whiletempnext.next!null
temp
Hint: what node does temp point to now?
temp.next
urations after executing deleteLast. Below is the code for the DeleteLast program public void deleteObject el find and remove el;
if head null if nonempty list;
if elequalsheadinfo if head needs to be removed;
head head.next;
else
SLLNode pred head, tmp head.next;
for ; tmp null && tmpinfo.equalsel;
pred pred.next, tmp tmpnext;
if tmp null if found
pred.next tmpnext;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
