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, i.e. 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 (head.next==null) The list has one node
head=???
}
else The list has at least two nodes
SLLNode temp=???// search for the next but last node....
while(temp.next.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 delete(Object el){// find and remove el;
if (head != null)// if non-empty list;
if (el.equals(head.info))// if head needs to be removed;
head = head.next;
else {
SLLNode pred = head, tmp = head.next;
for ( ; tmp != null && !(tmp.info.equals(el));
pred = pred.next, tmp = tmp.next);
if (tmp != null)// if found
pred.next = tmp.next;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!