Explanation of Solution
Code for creating a linked list of strings “red green blue”:
The code for creating a linked list of strings “red green blue” is given below:
Filename: “Node.java”
Refer “Node.java” from chapter 19 in the textbook.
Filename: “ExampleLinkedList.java”
//Define "ExampleLinkedList" class
public class ExampleLinkedList
{
//Define main function
public static void main(String[] args)
{
//Create a linked list using "Node" class
Node newList = new Node("red", new Node("green", new Node("blue")));
/* Set a reference "ref1" to the first node in the list "newList" */
Node ref1 = newList;
/* This loop will perform up to the reference "ref1" is equal to "null" */
while (ref1 != null)
{
/* Display the first node in the "ref1" */
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 19 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Let I be a list of integers. Below, there are four expressions that involve the list I. Without even knowing the contents of I, match the expressions to the lists that were evaluated from them. [sum (1[:i]) for i in range (len(1))] Choose. Choose. [1[0] for i in enumerate (1)] [0, 1, 2, 3, 4, 5, 6, 7, 8) fo, 49, 112, 148, 160, 251, 348, 366, 388] (1.7, 4, 4, 3, 1, 2, 6, 2] [97, 91, 63, 58, 49, 36, 22, 18, 12] [1776, 3162, 840, 0, 7110, 8160, 102, 210, 2622] [sorted (1) (i] for i in [8,7,6,5,4,3,2,1,01] [118 for i in 1] Choose. (1**2-13*1+12 for i in 1] Choose.arrow_forwardA contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings), separated by a comma. That list is followed by a name, and your program should output the phone number associated with that name. Output "None" if name is not found. Ex: If the input is: 3 Joe,123-5432 Linda,983-4123 Frank,867-5309 Frank the output is: 867-5309 Your program must define and call the following function. The return value of GetPhoneNumber is the phone number associated with the specific contact name.string GetPhoneNumber(vector<string> nameVec, vector<string> phoneNumberVec, string contactName) Hint: Use two vectors: One for the string names, and the other for the string phone numbers.arrow_forwardWrite a Java program that goes through Collection of Linked List elements of String data type and removes all the elements with string length of greater than five. Java Code +arrow_forward
- Given a singly linked list, reverse the list. This means you have to reverse every node. For example if there are 4 nodes, the node at position 0 will move to position 3, the node at 1 will move to position 2 and so on. You do not have to write the Node class just write what you have been asked to. You are NOT allowed to create a new list. In python languagearrow_forwardWrite in Java Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. For coding simplicity, follow each output word by a comma, even the last one. Add a newline to the end of the last output. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words.arrow_forwardArtificial Intelligence- Java program Write code that accomplishes the following tasks. Consider two bags that can hold strings. One bag is named letters and contain seeral one-letter strings. The other bag is empty and is namedvowels. One at a time removed a string from letters. If the string contain a vowel place it into bag vowels, otherwise, discard the string. After you have checked all of the strings in letters, report the number of vowels and the number of times each voewl appears in the bag.arrow_forward
- Apply the methods in the ListIterator interface to write a Java program in NetBeans that creates a LinkedList of four elements of type string, namely: Java, C#, PHP and Python. The program should then print out the elements initially in the original order, and then afterwards in reverse order using the ListIterator methods. In this case, the following is the expected output:arrow_forwardWe have a list that stores the repeated heart-rate measurements for the same patient over several tests. Each inner-list is a test and for that test, the heart rate is monitored for some time while taking a few measurements. Next, we would like to calculate the average of the measurements for each test.heart_rate = [ [ 72, 75, 71, 73], # resting[ 91, 90, 94, 93], # walking slowly[ 130, 135, 139, 142], # running on treadmill[ 120, 118, 110, 105, 100, 98]] # after minute recoveryIn your code, define a function calculate_average_heart_rates() that accepts the list heart_rate as its only input argument. Inside the function, use nested loops to calculate the average heart rate during each test scenario. This function should return a list that contains the average heart rate values of a patient for the four test scenarios.Write unit testsarrow_forwardGiven a ListItem class, complete main() using the built-in LinkedList type to create a linked list called shoppingList. The program should read items from input (ending with -1), adding each item to shoppingList, and output each item in shoppingList using the printNodeData() method. Ex. If the input is: milk bread eggs waffles cereal -1 the output is: milk bread eggs waffles cereal ShoppingList.java import java.util.Scanner;import java.util.LinkedList; public class ShoppingList {public static void main (String[] args) {Scanner scnr = new Scanner(System.in); // TODO: Declare a LinkedList called shoppingList of type ListItem String item;// TODO: Scan inputs (items) and add them to the shoppingList LinkedList// Read inputs until a -1 is input// TODO: Print the shoppingList LinkedList using the printNodeData() method }} ListItem.java public class ListItem {private String item; public ListItem() {item = "";} public ListItem(String itemInit) {this.item = itemInit;} // Print this node…arrow_forward
- Given a singly linked list containing numbers, print the numbers in a reverse manner. You do not have to write the Node class just write what you have been asked to. You are NOT allowed to create a new list. Write a program in python.arrow_forwardGiven that an ArrayList of Strings named friendList has already been created and names have already been inserted, write the statement necessary to change the name "Tyler", stored at index 8, to "Bud". This is needed in Javaarrow_forwardYou are going to implement a program that creates an unsorted list by using a linked list implemented by yourself. NOT allowed to use LinkedList class or any other classes that offers list functions. It is REQUIRED to use an ItemType class and a NodeType struct to solve this homework. The “data.txt” file has three lines of data 100, 110, 120, 130, 140, 150, 160 100, 130, 160 1@0, 2@3, 3@END You need to 1. create an empty unsorted list 2. add the numbers from the first line to list using putItem() function. Then print all the current keys to command line in one line using printAll(). 3. delete the numbers given by the second line in the list by using deleteItem() function. Then print all the current keys to command line in one line using printAll().. 4. putItem () the numbers in the third line of the data file to the corresponding location in the list. For example, 1@0 means adding number 1 at position 0 of the list. Then print all the current keys to command line in one…arrow_forward
- 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