Class 1: Gamer List
public class GamerList
{
private class Node
{
String name;
int score;
Node next;
Node(String Score1, int Score2)
{
name = Score1;
score = Score2;
}
}
private Node head;
public GamerList()
{
head = null;
}
public boolean isEmpty()
{
return head == null;
}
public int size()
{
int count = 0;
Node p = head;
while(p != null)
{
count++;
p = p.next;
}
return count;
}
public void insert(String name, int score)
{
Node node = new Node(name, score);
if(isEmpty())
{
head = node;
node.next = null;
}
else
{
Node curr = head;
Node prev = null;
while(curr != null && curr.score > node.score)
{
prev = curr;
curr = curr.next;
}
if(prev == null)
{
head = node;
node.next = curr;
}
else
{
prev.next = node;
node.next = curr;
}
}
if(size() > 10)
{
Node currentPtr = head;
for (int i = 0; i < 9; i++) {
currentPtr = currentPtr.next;
}
currentPtr.next = null;
}
}
public void printList() {
Node temp = head;
while(temp != null) {
System.out.print(temp.name + " " + temp.score + " ");
System.out.println("");
temp = temp.next;
}
}
}
Class 2: Player List
public class PlayerList {
public static void main(String[] args) {
GamerList list1 = new GamerList();
list1.insert("RED", 10);
list1.insert("ASS", 30);
list1.insert("PCP", 20);
list1.insert("ZDS", 50);
list1.insert("ZZZ", 60);
list1.insert("AAA", 40);
list1.insert("BBB",80);
list1.insert("CCC", 70);
list1.insert("REJ", 90);
list1.insert("SER", 100);
list1.insert("AZZ", 5);
list1.insert("JJJ", 15);
System.out.println ("GALAXIA");
System.out.println("HIGH SCORES" + " : ");
list1.printList();
}
}
public class GamerList
{
private class Node
{
String name;
int score;
Node next;
Node(String Score1, int Score2)
{
name = Score1;
score = Score2;
}
}
private Node head;
public GamerList()
{
head = null;
}
public boolean isEmpty()
{
return head == null;
}
public int size()
{
int count = 0;
Node p = head;
while(p != null)
{
count++;
p = p.next;
}
return count;
}
public void insert(String name, int score)
{
Node node = new Node(name, score);
if(isEmpty())
{
head = node;
node.next = null;
}
else
{
Node curr = head;
Node prev = null;
while(curr != null && curr.score > node.score)
{
prev = curr;
curr = curr.next;
}
if(prev == null)
{
head = node;
node.next = curr;
}
else
{
prev.next = node;
node.next = curr;
}
}
if(size() > 10)
{
Node currentPtr = head;
for (int i = 0; i < 9; i++) {
currentPtr = currentPtr.next;
}
currentPtr.next = null;
}
}
public void printList() {
Node temp = head;
while(temp != null) {
System.out.print(temp.name + " " + temp.score + " ");
System.out.println("");
temp = temp.next;
}
}
}
Class 2: Player List
public class PlayerList {
public static void main(String[] args) {
GamerList list1 = new GamerList();
list1.insert("RED", 10);
list1.insert("ASS", 30);
list1.insert("PCP", 20);
list1.insert("ZDS", 50);
list1.insert("ZZZ", 60);
list1.insert("AAA", 40);
list1.insert("BBB",80);
list1.insert("CCC", 70);
list1.insert("REJ", 90);
list1.insert("SER", 100);
list1.insert("AZZ", 5);
list1.insert("JJJ", 15);
System.out.println ("GALAXIA");
System.out.println("HIGH SCORES" + " : ");
list1.printList();
}
}