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 20 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- Write a program that prompts the user to input a string and then outputs the string in the pig Latin form. The rules for converting a string into pig Latin form are described in Programming Example: Pig Latin Strings Your program must store the characters of a string into a linked list and use the function rotate, as described in Programming rotate the string.arrow_forwardLet 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_forwardJava - Elements in a Rangearrow_forward
- In C++, write a program that outputs the nodes of a graph in a breadth first traversal. Data File: Please use this data file. Text to copy: 100 1 3 -9991 4 -9992 5 -9993 2 -9994 -9995 7 8 -9996 4 7 -9997 -9998 -9999 7 8 -999 Diagram: Also, please take a look at the attached figure on and calculate the weights for the following edges: 0 -> 1 -> 4 0 -> 3 -> 2 -> 5 -> 7 0 -> 3 -> 2 -> 5 -> 8 6 -> 4 6 -> 7 9 -> 7 9 -> 8 To calculates these weights, please assume the following data: 0 -> 1 = 1 0 -> 3 = 2 1 -> 4 = 3 3 -> 2 = 4 2 -> 5 = 5 5 -> 7 = 6 5 -> 8 = 7 6 -> 4 = 8 6 -> 7 = 9 9 -> 7 = 10 9 -> 8 = 11arrow_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_forwardGiven main() in the ShoppingList class, define an insertAtEnd() method in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list. The output is: Kale Lettuce Carrots Peanuts public class ItemNode { private String item; private ItemNode nextNodeRef; // Reference to the next node public ItemNode() { item = ""; nextNodeRef = null; } // Constructor public ItemNode(String itemInit) { this.item = itemInit; this.nextNodeRef = null; } // Constructor public ItemNode(String itemInit, ItemNode nextLoc) {…arrow_forward
- Write a program that inputs a list of integers from the user, and removes the duplicate list elements, plus outputs their min and max values.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_forwardComplete the function getLetterFrequency() to return a list containing the number of times each letter of the alphabet occurs in the string passed to it. The Oth index corresponds to the letter "a" or "A", the 1st corresponds to the letter "b" or "B", ..., the 25th corresponds to "z" or "Z". You should ignore any non-alphabet characters that occur in the string. But make sure that both lowercase and uppercase letters contribute to the same count. You must use the ord() function to convert letters into indexed based values. Note that you can offset a number by ord("a") or ord("A") to get the index that you need. You should use at least some of the (or all of) following string methods: • isalpha() lower() • upper() • isupper() • islower() and the following string functions: ord() len()arrow_forward
- in this assignment i have to remove vowels from a string using a linked list. the linked list and link code is from a textbook and cannot be changed if the code alters the data structure. for some reason when i implement this code it gives me a logical error where the program only removes all instances of the first vowel in a string instead of moving through all vowels of the string and removing each one with all instances. i would appreciate if you could tell me the problem and solution in words and not in code. The code is in java. output please enter a string.researchhcraeserfalseList (first -->last): researchList (first -->last): researchList (first -->last): rsarch CODE MAIN FUNCTION import java.util.Scanner;/*** Write a description of class test here.** @author (your name)* @version (a version number or a date)*/public class test{// instance variables - replace the example below with your ownpublic static void main(String[] args){Scanner input = new…arrow_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_forwardIn C++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