Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
bartleby

Concept explainers

Question
Book Icon
Chapter 3, Problem 38P
Program Plan Intro

Game application using doubly linked list

Program plan:

  • Create a class Node.
    • Construct the empty list using default constructor.
    • Initialize the required variables using the parameterized constructor.
    • Set the scores using the setScore() method.
    • Set the name of the game using setName() method.
    • Set the previous node of score using setPrev() method.
    • Set the next node of score using setNext() method.
    • Get the score using getScore() method.
    • Get the name of game using getName() method.
    • Get the previous node of score using getPrev() method.
    • Get the next node of score using getNext() method.
  • Create a class ScoresList.
    • In the add() method,
      • Adds a new score to the list of scores.
        • In the remove() method,
          • Delete a score from the list of scores.
        • In the display() method,
          • Displays the top ten scores.
  • Create a class Main.
    • In main() method.
      • Create an object for scanner class.
      • Read the input from user.
      • Call add() method and remove() method.
      • Finally, display top ten score from the list.

Blurred answer
Students have asked these similar questions
Add a new public member function to the LinkedList class named reverse() which reverses the items in the list.  You must take advantage of the doubly-linked list structure to do this efficiently as discussed in the videos/pdfs, i.e. swap each node’s prev/next pointers, and finally swap headPtr/tailPtr.  Demonstrate your function works by creating a sample list of a few entries in main(), printing out the contents of the list, reversing the list, and then printing out the contents of the list again to show that the list has been reversed.   Note: your function must actually reverse the items in the doubly-linked list, not just print them out in reverse order! Note: we won't use the copy constructor in this assignment, and as such you aren't required to update the copy constructor to work with a doubly-linked list.   This is what I have so far but its not working! template<class ItemType>void LinkedList<ItemType>::reverse(){   Node<ItemType>*curPtr,*prev,*next;…
Implement a recursive function void deleteMax() on the IntList class (provided). The function will delete from the IntList the IntNode containing the largest value. If there are multiple nodes containing this largest value, only delete the 1st one. Be careful not to cause any memory leaks or dangling pointers. You may NOT use any kind of loop (must use recursion). You may NOT use global or static variables. You may NOT use any standard library functions.   Ex: list: 5->7->1->16->4->16->3 list.deleteMax(); list: 5->7->1->4->16->3   IntList.h #ifndef __INTLIST_H__#define __INTLIST_H__ #include <ostream> using namespace std; struct IntNode {int value;IntNode *next;IntNode(int value) : value(value), next(nullptr) {}}; class IntList { private:IntNode *head; public: /* Initializes an empty list.*/IntList() : head(nullptr) {} /* Inserts a data value to the front of the list.*/void push_front(int val) {if (!head) {head = new IntNode(val);} else {IntNode…
You are required to complete the LinkedList class. This class is used as a linked list that has many methods to perform operations on the linked list. To create a linked list, create an object of this class and use the addFirst or addLast or add(must be completed) to add nodes to this linked list. Your job is to complete the empty methods. For every method you have to complete, you are provided with a header, Do not modify those headers(method name, return type or parameters). You have to complete the body of the method. package chapter02;

public class LinkedList
{
   protected LLNode list;

   public LinkedList()
   {
      list = null;
   }

   public void addFirst(T info)
   {
      LLNode node = new LLNode(info);
      node.setLink(list);
      list = node;
   }

   public void addLast(T info)
   {
      LLNode curr = list;

      LLNode newNode = new LLNode(info);
      if(curr == null)
      {
         list = newNode;
      }
      else
      {
         while(curr.getLink() !=…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education