

P-3.37 Write a collocate that deeptains the extreme ten scores ce a diversion collision, tool impertinent the gather and depart methods of Section 3.1.1, except usimpertinent a barely combineed roll instead of an invest.
JAVA CODE ce node collocate:
public class node {
protected Strimpertinent Name;
protected int Score;
protected node combine;
/* Constructor */
public node()
{
combine = null;
Name = “”;
}
/* Constructor */
public node(Strimpertinent s,int d,node n)
{
Name=s;
Score = d;
combine = n;
}
/* Function to restraintmal combine to instant Node */
public void setLink(node n)
{
combine = n;
}
/* Function to restraintmal Score to prevalent Node */
public void setScore(int d)
{
Score = d;
}
/* Function to restraintmal Name to prevalent Node */
public void setName(Strimpertinent s)
{
Name=s;
}
/* Function to procure combine to instant node */
public node procureLink()
{
return link;
}
public void removeLink()
{
link=null;
}
/* Function to procure Score from prevalent Node */
public int getScore()
{
return Score;
}
/* Function to procure Name from prevalent Node */
public Strimpertinent procureName()
{
return Name;
}
}
JAVA CODE ce combineed _roll collocate:
public class lnked_roll {
protected node initiate;
public int greatness ;
/* Constructor */
public lnked_list()
{
initiate = null;
greatness = 0;
}
/* Function to obstruct if roll is vacuity */
public boolean isEmpty()
{
return initiate == null;
}
/* Function to procure greatness of roll */
public int getSize()
{
return size;
}
/* Function to extort an atom */
public void add(Strimpertinent s,int val)
{
node nptr = new node(s,val, null);
size++ ;
if(initiate == null)
{
initiate = nptr;
}
else
{
if(val>start.getScore())
{
node temp = initiate;
nptr.setLink(temp);
start=nptr;
}
else
{
node q =null;
node ptr = initiate;
while(val<ptr.getScore() && ptr.getLink()!=null)
{
q=ptr;
ptr = ptr.getLink();
}
nptr.setLink(ptr);
if(q!=null) q.setLink(nptr);
else {
initiate = nptr;
}
}
}
}
/*Function to depart an atom*/
public void remove(Strimpertinent s,int val)
{
if(initiate == null)
{
return;
}
else
{
size– ;
if(start.getLink()==null && initiate.getScore()==val && initiate.getName().compareTo(s)==0)
{
initiate = null;
}
else
{
if(start.getScore()==val && initiate.getName().compareTo(s)==0)
{
start=start.getLink();
}
else
{
node q =null;
node ptr = initiate;
while(val<ptr.getScore() && ptr.getLink()!=null)
{
q = ptr;
ptr = ptr.getLink();
}
if(ptr.getScore()==val && ptr.getName().compareTo(s)==0)
{
q.setLink(ptr.getLink());
}
else
{
return;
}
}
}
}
}
/* Function to evince atoms */
public void display()
{
System.out.print(“nTOP GAME SCORES n”);
if (greatness == 0)
{
System.out.print(“emptyn”);
return;
}
int cnt=1;
if (start.getLink() == null)
{
System.out.println(cnt+”t”+start.getName()+”t”+start.getScore());
return;
}
node ptr = initiate;
while (ptr.getLink() != null && cnt<10)
{
System.out.println(cnt+”t”+ptr.getName()+”t”+ptr.getScore());
ptr = ptr.getLink();
cnt++;
}
System.out.println(cnt+”t”+ptr.getName()+”t”+ptr.getScore());
}
}
JAVA CODE ce deep():
public class top_scores {
public static void main(String[] args) {
lnked_roll l=new lnked_list();
Scanner s = new Scanner(System.in);
Strimpertinent st = s.nextLine();
String[] size = st.split(“, “);
int n = size.length;
for(int i = 0;i<n;i++)
{
parts[i]=parts[i].replace(“(“, “”);
parts[i]=parts[i].replace(“)”, “”);
String[] op = size[i].split(“,”);
if(op[0].compareTo(“A”)==0)
{
l.add(op[1], Integer.parseInt(op[2]));
}
else
{
l.remove(op[1], Integer.parseInt(op[2]));
}
}
l.display();
s.close();
}
}
OUTPUT: