Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
- In the remove() method,
- Adds a new score to the list of scores.
- In the add() method,
- 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.
- In main() method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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…
Important: Make all your implementation in the same attached file and submit only one file in the
submission link.
Given the linked list data structure discussed in the lecture, implement a sub-class
TSortedList that makes sure that elements are inserted and maintained in an ascending
order in the list. So, given the input sequence {1,7,3,11,5}, when printing the list after
inserting the last element it should print like 1, 3, 5, 7, 11. Note that with inheritance, you
have to only care about the insertion situation as deletion should still be handled by the
parent class.
In the basic implementation, assume that you only have head which is a pointer to the
head of the list. Now, if we have both head and tail pointers, what improvements can be
done to speed up the insertion?
Chapter 3 Solutions
Data Structures and Algorithms in Java
Ch. 3 - Prob. 1RCh. 3 - Write a Java method that repeatedly selects and...Ch. 3 - Prob. 3RCh. 3 - The TicTacToe class of Code Fragments 3.9 and 3.10...Ch. 3 - Prob. 5RCh. 3 - Prob. 6RCh. 3 - Prob. 7RCh. 3 - Prob. 8RCh. 3 - Prob. 9RCh. 3 - Prob. 10R
Ch. 3 - Prob. 11RCh. 3 - Prob. 12RCh. 3 - Prob. 13RCh. 3 - Prob. 14RCh. 3 - Prob. 15RCh. 3 - Prob. 16RCh. 3 - Prob. 17CCh. 3 - Prob. 18CCh. 3 - Prob. 19CCh. 3 - Give examples of values for a and b in the...Ch. 3 - Suppose you are given an array, A, containing 100...Ch. 3 - Write a method, shuffle(A), that rearranges the...Ch. 3 - Suppose you are designing a multiplayer game that...Ch. 3 - Write a Java method that takes two...Ch. 3 - Prob. 25CCh. 3 - Prob. 26CCh. 3 - Prob. 27CCh. 3 - Prob. 28CCh. 3 - Prob. 29CCh. 3 - Prob. 30CCh. 3 - Prob. 31CCh. 3 - Prob. 32CCh. 3 - Prob. 33CCh. 3 - Prob. 34CCh. 3 - Prob. 35CCh. 3 - Write a Java program for a matrix class that can...Ch. 3 - Write a class that maintains the top ten scores...Ch. 3 - Prob. 38PCh. 3 - Write a program that can perform the Caesar cipher...Ch. 3 - Prob. 40PCh. 3 - Prob. 41PCh. 3 - Prob. 42PCh. 3 - Prob. 43P
Knowledge Booster
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
- 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() !=…arrow_forwardWrite and implement a recursive version of the binary search algorithm. Also, write a version of the sequential search algorithm that can be applied to sorted lists. Add this operation to the class orderedArrayListType for array-based lists. Moreover, write a test program to test your algorithm.arrow_forwardImplements clone which duplicates a list. Pay attention, because if there are sublists, they must be duplicated as well. Understand the implementation of the following function, which recursively displays the ids of each node in a list Develop your solution as follows: First copy the nodes of the current list (self) Create a new list with the copied nodes Loop through the nodes of the new list checking the value field If this field is also a list (use isinstance as in the show_ids function) then it calls clone on that list and substitutes the value. Complete the code: def L4(*args,**kwargs): class L4_class(L): def clone(self): def clone_node(node): return <... YOUR CODE HERE ...> r = <... YOUR CODE HERE...> return r return L4_class(*args,**kwargs)arrow_forward
- For the AVLTree class, create a deletion function that makes use of lazy deletion.There are a number of methods you can employ, but one that is straightforward is to merely include a Boolean field in the Node class that indicates whether or not the node is designated for elimination. Then, your other approaches must take into consideration this field.arrow_forwardUse java and indent code properly.arrow_forwardIn this question, you are to implement two functions for reversing linked lists. One function, reverse_iter(..), must use an iterative approach (i.e., loops), whereas the other function, reverse_rec(..), must use recursion instead. We have already implemented the linked list as well as all its helper-functions in the Ilist-module.arrow_forward
- Measure the performance of addFirst, remove(Object), and removeLast for each of the three implementations (you may include Vectors, if you wish). Which implementations perform best for small lists? Which implementations perform best for large lists?arrow_forwardImplement a function to insert a node at the end of a doubly linked list. Explain the steps involved and analyze the time complexity of your implementation.arrow_forwardImplement a list of employees using a dynamic array of strings.Your solution should include functions for printing list, inserting and removingemployees, and sorting lists (use Bubble sort in C++ language).Keep list of employees sorted within the list after insertion.See the following example:How many employees do you expect to have?5 (Carriage Return)Menu :1 . Print full list of employees2 . Insert new employee3 . Remove employee from list0 . Exit2 (Carriage Return)Input name of new employee : MikeMenu :1 . Print full list of employees2 . Insert new employee3 . Remove employee from list0 . Exit1(Carriage Return)1 . MaryMenu :1 . Print full list of employees2 . Insert new employee3 . Remove employee from list0 . Exitarrow_forward
- 1. Consider an ADT list of integers. Write a method that computes the maximum of the integers in the list aList. The definition of your method should be indepen- dent of the list's implementation.arrow_forwardIn python. Write a LinkedList class that has recursive implementations of the add and remove methods. It should also have recursive implementations of the contains, insert, and reverse methods. The reverse method should not change the data value each node holds - it must rearrange the order of the nodes in the linked list (by changing the next value each node holds). It should have a recursive method named to_plain_list that takes no parameters (unless they have default arguments) and returns a regular Python list that has the same values (from the data attribute of the Node objects), in the same order, as the current state of the linked list. The head data member of the LinkedList class must be private and have a get method defined (named get_head). It should return the first Node in the list (not the value inside it). As in the iterative LinkedList in the exploration, the data members of the Node class don't have to be private. The reason for that is because Node is a trivial class…arrow_forwardYou have an empty linked list, implemented using an array. Show how you insert all the elements one by one to the list. You need to insert the elements in given order (You can sketch your answer on a piece of paper 10, 8, 20, 6, 3, 40, 25arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education