Question: Using Arrays Using Singly Linked List Using Doubly Linked List Problem 1 : Write the Java code for performing add ( e ) and remove
Using Arrays
Using Singly Linked List
Using Doubly Linked List
Problem : Write the Java code for performing adde and removee methods for the
Scoreboard class, as shown below, except this time, dont maintain the game entries in
order. Assume that we still need to keep n entries stored in indices to n You should
be able to implement the methods without any loop so that the number of steps they
perform does not depend on n Create a Driver class to test your code.
CSC Fundamental Data Structures Page of Class for storing high scores in an array in nondecreasing order.
public class Scoreboard
private int numEntries ; number of actual entries
private GameEntry board;
array of game entries names & scores
Constructs an empty scoreboard with the given capacity for storing entries.
public Scoreboardint capacity
board new GameEntrycapacity;
Attempt to add a new score to the collection if it is high enough
public void addGameEntry e
int newScore egetScore;
is the new entry e really a high score?
if numEntries board.length newScore boardnumEntriesgetScore
if numEntries board.length
no score drops from the board
numEntries;
so overall number increases
shift any lower scores rightward to make room for the new entry
int numEntries ;
while && board getScore newScore
boardj boardj; shift entry from to
j; and decrement
boardj e; when done, add new entry
Remove and return the high score at index i
public GameEntry removeint i throws IndexOutOfBoundsException
if :: numEntries
throw new IndexOutOfBoundsExceptionInvalid index: i;
GameEntry temp boardi; save the object to be removed
for int ; numEntries ; count up from not down
boardj boardj; move one cell to the left
boardnumEntries null; null out the old last score
numEntries;
return temp;
return the removed object
Problem : Write a class that maintains the top ten scores for a game
application, implementing the add and remove methods as discussed in the
previous problem, but using a Singly Linked List instead of an array. Create a
Driver class to test your code.
Problem : Perform the previous problem using a Doubly Linked List. Your
implementation of the remove method should make the fewest number of pointer
hops to get to the game entry. Create a Driver class to test your code.
CSC Fundamental Data Structures Page of
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
