Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 18, Problem 2FTE
Explanation of Solution
Given statements:
//implement the "List" interface
List <String> nameList = new ArrayList<>();//Line 1
//declare the "ListIterator"
ListIterator it = new ListIterator(nameList); //Line 2
Error in the statement:
Error #1:
The error is in “Line 2”. For obtaining the list iterator for the variable “nameList” the user need to call its list iterator method.
Correct statement:
//declare the "ListIterator"
ListIterator <String> it = nameList...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Q: Convert this to sorted array
#include<iostream>
#include"Student.cpp"
class StudentList
{
private:
struct ListNode
{
Student astudent;
ListNode *next;
};
ListNode *head;
public:
StudentList();
~StudentList();
int IsEmpty();
void Add(Student newstudent); void Remove();
void DisplayList();
};
StudentList::StudentList() {
head=NULL;
};
StudentList::~StudentList()
{
cout <<"\nDestructing the objects..\n";
while(IsEmpty()!=0)
Remove();
if(IsEmpty()==0)
cout <<"All students have been deleted from a list\n"; };
int StudentList::IsEmpty()
{
if(head==NULL)
return 0;
else
return 1;
};
void StudentList::Add(Student newstudent) {
ListNode *newPtr=new ListNode;
if(newPtr==NULL)
cout <<"Cannot allocate memory";
else
{
newPtr->astudent=newstudent;
newPtr->next=head;
head=newPtr;
}
};
void StudentList::Remove() {
if(IsEmpty()==0)
cout <<"List empty on remove"; else
{
ListNode *temp=head;…
Question 9
#include
using namespace std;
struct ListNode {
string data;
ListNode *next;
};
int main() {
ListNode *ptr, *list;
list = new ListNode;
list->data = "New York";
ptr = new ListNode;
ptr->data = "Boston";
list->next = ptr;
ptr->next = new ListNode;
ptr->next->data = "Houston";
ptr->next->next = nullptr;
// new code goes here
Which of the following code correctly deletes the last node of the list when added at point of insertion indicated above?
O delete ptr->next;
ptr->next = nullptr;;
O ptr = list;
while (ptr != nullptr)
ptr = ptr->next;
delete ptr;
O ptr = last;
delete ptr;
list->next->next =
nullptr;
delete ptr;
O None of these
Question 6
The default capacity of ArrayList object is:
10
50
Capacity must be specified by the user.
100
Chapter 18 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 18.1 - Prob. 18.1CPCh. 18.1 - What are the three general types of collections?Ch. 18.1 - Prob. 18.3CPCh. 18.1 - Prob. 18.4CPCh. 18.1 - Prob. 18.5CPCh. 18.1 - Prob. 18.6CPCh. 18.1 - Prob. 18.7CPCh. 18.2 - Prob. 18.8CPCh. 18.2 - Prob. 18.9CPCh. 18.2 - Prob. 18.10CP
Ch. 18.2 - Prob. 18.11CPCh. 18.2 - Prob. 18.12CPCh. 18.2 - Prob. 18.13CPCh. 18.2 - Prob. 18.14CPCh. 18.2 - Prob. 18.16CPCh. 18.2 - Prob. 18.17CPCh. 18.2 - Prob. 18.18CPCh. 18.2 - Prob. 18.20CPCh. 18.3 - Prob. 18.21CPCh. 18.3 - Prob. 18.22CPCh. 18.3 - Prob. 18.23CPCh. 18.3 - Prob. 18.24CPCh. 18.3 - Any time you override the Object classs equals...Ch. 18.3 - Prob. 18.26CPCh. 18.3 - Prob. 18.27CPCh. 18.3 - Prob. 18.28CPCh. 18.4 - Prob. 18.29CPCh. 18.4 - Prob. 18.31CPCh. 18.4 - Prob. 18.32CPCh. 18.6 - How do you define a stream of elements?Ch. 18.6 - How does a stream intermediate operation differ...Ch. 18.6 - Prob. 18.35CPCh. 18.6 - Prob. 18.36CPCh. 18.6 - Prob. 18.37CPCh. 18.6 - Prob. 18.38CPCh. 18.6 - Prob. 18.39CPCh. 18 - Prob. 1MCCh. 18 - Prob. 2MCCh. 18 - This type of collection is optimized for...Ch. 18 - Prob. 4MCCh. 18 - A terminal operation in a stream pipeline is also...Ch. 18 - Prob. 6MCCh. 18 - Prob. 7MCCh. 18 - This List Iterator method replaces an existing...Ch. 18 - Prob. 9MCCh. 18 - Prob. 10MCCh. 18 - This is an object that can compare two other...Ch. 18 - This class provides numerous static methods that...Ch. 18 - Prob. 13MCCh. 18 - Prob. 14MCCh. 18 - Prob. 15TFCh. 18 - Prob. 16TFCh. 18 - Prob. 17TFCh. 18 - Prob. 18TFCh. 18 - Prob. 19TFCh. 18 - Prob. 20TFCh. 18 - Prob. 21TFCh. 18 - Prob. 22TFCh. 18 - Prob. 1FTECh. 18 - Prob. 2FTECh. 18 - Prob. 3FTECh. 18 - Prob. 4FTECh. 18 - Write a statement that declares a List reference...Ch. 18 - Prob. 2AWCh. 18 - Assume that it references a newly created iterator...Ch. 18 - Prob. 4AWCh. 18 - Prob. 2SACh. 18 - Prob. 4SACh. 18 - Prob. 5SACh. 18 - Prob. 6SACh. 18 - How does the Java compiler process an enhanced for...Ch. 18 - Prob. 8SACh. 18 - Prob. 9SACh. 18 - Prob. 10SACh. 18 - Prob. 11SACh. 18 - Prob. 12SACh. 18 - Prob. 13SACh. 18 - Prob. 14SACh. 18 - Word Set Write an application that reads a line of...Ch. 18 - Prob. 3PCCh. 18 - Prob. 5PCCh. 18 - Prob. 8PC
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
- #include <iostream>#include <vector>using namespace std; void PrintVectors(vector<int> numsList) { unsigned int i; for (i = 0; i < numsList.size(); ++i) { cout << numsList.at(i) << " "; } cout << endl;} int main() { vector<int> numsList; int userInput; int i; for (i = 0; i < 3; ++i) { cin >> userInput; numsList.push_back(userInput); } numsList.erase(numsList.begin()+1); numsList.insert(numsList.begin()+1, 102); numsList.insert(numsList.begin()+1, 100); PrintVectors(numsList); return 0;} Not all tests passed clearTesting with inputs: 33 200 10 Output differs. See highlights below. Special character legend Your output 33 100 102 10 Expected output 100 33 102 10 clearTesting with inputs: 6 7 8 Output differs. See highlights below. Special character legend Your output 6 100 102 8 Expected output 100 6 102 8 Not sure what I did wrong but the the 33…arrow_forwardstruct Node { int data; Node * next; }; Node • head; a. Write a function named addNode that takes in a variable of type int and inserts it at the head of the list. b. Write a function named removeNode that removes a node at the head of the list.arrow_forwardWhat benefits do enumeration types provide over a collection of named constants? What benefits does a subrange type have over its base type? When might a string be preferable over a character array?arrow_forward
- 8arrow_forwardPart 1: Add the code of the ArrayListType to your code. Part 2: Create an Ordered_List class derived from the ArrayListType then add the following function to this class: Constructor to create an array of the size specified by the parameter size. The default array size is 20. Sorted Insert this function takes an integer values then add it to the list this function should check whether the value exist in the list or not. If it is already exist then it will not be inserted to the list, this function should keep the list ordered. Remove function to remove an item from the list. The function takes a single parameter that specifies the number to be removed. • Sequential Search a function to search the list for an integer if exist return its location otherwise return -1. This function specifies the number we are looking for as a parameter. Part 3: Implement the following non-member functions to deal with the Ordered List objects: Load file: this function should read a text file consist an…arrow_forwardPart 1: Add the code of the ArrayListType to your code. Part 2: Create an Ordered_List class derived from the ArrayListType then add the following function to this class: Constructor to create an array of the size specified by the parameter size. The default array size is 20. Sorted Insert this function takes an integer values then add it to the list this function should check whether the value exist in the list or not. If it is already exist then it will not be inserted to the list, this function should keep the list ordered. Remove function to remove an item from the list. The function takes a single parameter that specifies the number to be removed. • Sequential Search a function to search the list for an integer if exist return its location otherwise return -1. This function specifies the number we are looking for as a parameter. Part 3: Implement the following non-member functions to deal with the Ordered List objects: Load file: this function should read a text file consist an…arrow_forward
- ignore the 4a is actually the previous I donearrow_forwardExercise, maxCylinderVolume F# system function such as min or methods in the list module such as List.map are not allowed Write a function maxCylinderVolume that takes a list of floating-point tuples that represent dimensions of a cylinder and returns the volume of the cylinder that has the largest volume. Each tuple has two floating point values that are both greater than zero. The first value is the radius r and the second value is the height h. The volume of the cylinder is computed using ??2h. The value π is represented in F# with System.Math.PI. If the list is empty, return 0.0. Examples: > maxCylinderVolume [(2.1, 3.4); (4.7, 2.8); (0.9, 6.1); (3.2, 5.4)];;val it : float = 194.3137888> maxCylinderVolume [(0.33, 0.66)];;val it : float = 0.2257988304arrow_forwardAn iterable is an object that is similar to a list and is created by the range function True or Falsearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT