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)
- Write a program in Java to implement a Singly linked list with two fields: String name and Integer Age. a) Then, Program ask user to enter name and age of a student, and add the node in the link list b) Store name and age of 5 students c) Then, traverse the link List to print all the nodesarrow_forwardWrite a program that reads a list of words from standard input and prints all twoword compound words in the list. For example, if after, thought, and afterthought are in the list, then afterthought is a compound word.arrow_forwardWrite a Python program that creates a linked list with 10000 nodes. Each node has arandom number between -1000 and 1000. Write a Python program that sort the linked list of above question in ascending order using theinsertion sort.arrow_forward
- •Implement a Linked List which accepts a string input, the linked list should also have the following functionalities: searching for a character, adding a character, traversing through charactersarrow_forwardCreate a Java program to find middle node of linked list in Java in one pass?arrow_forwardApply 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: Run: original order of strings: Java C# PHP Python Reverse order of strings: Python PHP C#Java BUILD SUCCESSFULarrow_forward
- Write a method find() that takes a linked list and a string key as arguments and returns true if some node in the list has key as its item field, false otherwise.arrow_forwardExecute a program that will split a circularly linked list P with n nodes intotwo circularly linked lists P1, P2 with the first n/2 and the last n – n/2 nodes ofthe list P in them.arrow_forwardImplement a nested class DoubleNode for creating doubly-linked lists, with each node containing a reference to the item before and following it in the list (empty if no such item exists). Then, for the following jobs, implement static methods: insert at the beginning, insert at the end, remove from the beginning, remove from the end, insert before a given node, insert after a given node, and remove a given node.arrow_forward
- Imagine you have an empty Queue of integers, Q, with 5 elements size, and two integer numbers x and y. Draw a picture of Q, x and y after executing the following code:arrow_forwardFOR JAVA Consider rewriting the method max() given below such that it gives the correct answer even if the linked list contains positive and/or negative integers on their .item variable. public int max(Node x) { intmaxValue=0; while(x!=null){ if(x.item<maxValue)maxValue=x.item; x=x.next; } returnmaxValue; } }arrow_forwardImplement a nested class DoubleNode for building doubly-linked lists, whereeach node contains a reference to the item preceding it and the item following it in thelist (null if there is no such item). Then implement static methods for the followingtasks: insert at the beginning, insert at the end, remove from the beginning, removefrom the end, insert before a given node, insert after a given node, and remove a givennode.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