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 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_forwardWrite 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_forward
- Java - Mileage for a Runnerarrow_forwardJava - Elements in a Rangearrow_forwardIn 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_forward
- Write a program that prompts the user to input a string and then outputs the string in PigLatin. Create the program using a Linked List. The linked list should have function that prints the linked list. This function should be a recursive function.arrow_forwardGiven 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_forwardJavaarrow_forward
- Given 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_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_forwardHow do I code the interfaces, classes and JUnit 4 tests in java? this is all the information given below: A sentence in English is made of several words in a particular sequence. You must represent such a sentence as a list of words. Much like the list example we saw in class, this one is made of nodes (represented by a Sentence interface). There is one word per node, called WordNode. The sentence may also contain zero or more punctuation marks, which are represented by a PunctuationNode. The end of the sentence is denoted by a special empty node, called EmptyNode. Define the following operations for such a list of words: A method getNumberOfWords that computes and returns the number of words in a sentence. The punctuation does not count as a word. This method should answer/return an int. A method longestWord that determines and returns the longest word in a sentence. The word returned is just the word, and should not begin or end with punctuation. If the sentence contains no…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