CODE:
import java.util.Scanner;
import java.util.LinkedList;
public class LinkedList1Demo
{
private LinkedList<String> s;
public static void main(String[] args)
{
LinkedList1Demo hScore = new LinkedList1Demo();
Scanner scanner = new Scanner(System.in);
while (true)
{
try
{
System.out.print("Enter the name (Or) -1 to quit: ");
String name = scanner.nextLine();
if ("-1".equals(name))
{
break;
}
System.out.print("Enter the high score:");
String score = scanner.nextLine();
hScore.insert(name, Integer.parseInt(score));
}
catch (Exception le)
{
System.out.println("Invalid data "+le);
le.printStackTrace();
}
}
System.out.println("High scores order:");
System.out.println(hScore.toString());
}
public LinkedList1Demo( )
{
s= new LinkedList<String>();
}
public void insert(String name, Integer score)
{
String newScore = name + " " + score.toString();
if (s.isEmpty( ))
{
s.add(newScore);
return;
}
for (int i = 0; i <= s.size(); i++)
{
if (i == s.size())
{
s.add(newScore);
break;
}
if (isCheck(newScore, s.get(i)))
{
s.add(i, newScore);
break;
}
}
while (s.size() > 10)
{
s.remove(10);
}
}
public boolean isCheck(String high, String low)
{
Integer highScore =
Integer.parseInt(high.substring(high.lastIndexOf(' ')+1));
Integer lowScore = Integer.parseInt(low.substring(low.lastIndexOf('
')+1));
return highScore > lowScore;
}
public String toString()
{
String sList = "";
for (int i = 0; i < s.size(); i++)
{
sList = sList + s.get(i) + "\n";
}
return sList;
}
}
Output:
Implement an application based on a singly linked list that maintains a list of the top...
JAVA please Java problem that has to be in doubly linked list. It is game problem that I have to keep of the players' scores. this should have a Java blueprint class named player It should have two fields, the name and score and include the constructors, toString() method, and getters and setters. Scores must be kept in ascending order (smallest at the front ) in a doubly linked list. It has menu as well: Load original data Print the...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...
how to implement a linked list object using only singly linked list toolkit. Then implement a FREQUENCY function to count the ovcurrence of each element in the list. task#1: Add = operator to node: implement the assignment operator for the node such that setting a node = overwrites the value in the node with the value. task#2:Linked List class implement the methods of linked list. insert search and locate remove node* operator [] task#3: Implement the Frequency
Q.(1)Describe the algorithm and java implementation for the following operations A. Create a singly linked list L1 with 4 nodes. You can use insert operation to add nodes to the list. Each element represent an airport code (e.g. BOS, ATL, JFK, MSP, etc.). Display the list L1 after it is created. B. Given singly linked list L1, create another singly linked list L2 that contains the same elements but in the reverse order. Display the content of both L1 and...
In NetBeans Create a new Java Application to manage Linked Lists: (Note: Do not use java.util.LinkedList) a) Create a DateTime class 1. Add day, month, year, hours, minutes as attributes 2. Add a constructor and a toString() method 3. Implement the Comparable interface, and add a CompareTo() method 4. Add methods to get and set all attributes. b) Add to MyLinkedList class the following methods: 1. Insert a Node to a particular position in the List 2. Insert a Node...
Answer all questions
1- in circular singly linked list, previous pointer of the first node points to which node A. First node B. Itself C. null D. Last node 2- Which of the following is NOT an applications of linked lists? A. Implementation of stacks and queues B. Dynamic memory allocation C. Manipulation of polynomials D. Keeping people at home during epidemics like corona virus 3- In a circular singly linked list? A. Components are all linked together in some...
In C++ - Learn how to implement linked lists Part 1 Node and Linked List Class (50 pts): Create node with public properties: Block type block and block ptr next. Create a linked list class that uses the node you generated without an add or delete method with a head and optional tail and counter. Make a driver that generates a node to test your implementation. Part 2 Add Method (30 pts): Create an add method in your linked list...