Question: 1 . In the driver, exercise twelve various insersion and deletion operations. 2 . If duplication is found for inserion, the program provides a message,

1. In the driver, exercise twelve various insersion and deletion operations.
2.If duplication is found for inserion, the program provides a message, and does not insert duplicated magzine.
3. If no title is found in deletion operation, the program provides a message, and does not delete any magazin.
Code:
public class MagazineList
{
private MagazineNode list;
//---------------------------------------------------------
-------
// Sets up an initially empty list of magazines.
//---------------------------------------------------------
-------
public MagazineList()
{
list = null;
}
//---------------------------------------------------------
-------
// Creates a new MagazineNode object and adds it to the
end of
// the linked list.
//---------------------------------------------------------
-------
public void add(Magazine mag)
{
MagazineNode node = new MagazineNode(mag);
MagazineNode current;
if (list == null)
list = node;
else
{
current = list;
while (current.next != null)
current = current.next;
current.next = node;
}
}
//------------------------------------------------------------
----
// Returns this list of magazines as a string.
//------------------------------------------------------------
----
public String toString()
{
String result ="";
MagazineNode current = list;
while (current != null)
{
result += current.magazine +"
";
current = current.next;
}
return result;
}
//*****************************************************************
// An inner class that represents a node in the magazine
list.
// The public variables are accessed by the MagazineList
class.
//*****************************************************************
private class MagazineNode
{
public Magazine magazine;
public MagazineNode next;
//------------------------------------------------------
--------
// Sets up the node
//------------------------------------------------------
--------
public MagazineNode(Magazine mag)
{
magazine = mag;
next = null;
}
}
}

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 Programming Questions!