Concept explainers
Explanation of Solution
Given code:
The given code fragment is highlighted.
Filename: “ListNode.java”
//Define "ListNode" class
public class ListNode
{
/* Refer the textbook of Listing 12.4 */
}
Filename: “StringLinkedList.java”
//Define "StringLinkedList" class
public class StringLinkedList
{
/* Refer the textbook of Listing 12.5 */
}
Filename: “StringLinkedListDemo.java”
//Define "StringLinkedListDemo" class
public class StringLinkedListDemo
{
//Define main function
public static void main(String[] args)
{
/* Create object "list" from "StringLinkedList" class */
StringLinkedList list = new StringLinkedList();
/* Add value to node using "addANodeToStart" method */
list.addANodeToStart("A");
list.addANodeToStart("B");
list.addANodeToStart("C");
/* Call the method "showList()" to display the element on the list */
list.showList();
}
}
Reasons for displaying given output:
From the given code,
- The first line “StringLinkedList list = new StringLinkedList();” is used to Create object “list” from “StringLinkedList” class...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- A c++ code that performs a search for a specific employee and returns the employee ID if found and 0 if not: int findEmployeeById(Employee list[], int size, int myId)arrow_forward#What is the output when the following code is executed? colorPalette = 'Modern' colorScheme = 'Garden' colorList = if 'Pink' in colorList or colorList[3] ['Yellow', 'Purple', 'Green', 'Orange'] == 'Purple ': colorPalette = 'Floral' print (colorPalette) else: if len (colorList) <= 4 and colorList[0] != colorPalette = 'Foliage' colorScheme = 'Nature else: colorScheme = 'Forest' print (colorScheme) print (colorPalette) print (colorScheme) print (colorList [2])arrow_forwardFor any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a comma (no spaces). Ex: If the input is: 32 105 101 35 10 20 30 40 the output is: 20,30, 1 #include 2 3 int main(void) { const int SIZE_LIST = 4; int keysList[SIZE_LIST]; int itemsList[SIZE_LIST]; int i; 4 6 7 8 scanf("%d", &keysList[0]); scanf ("%d", &keysList[1]); scanf("%d", &keysList[2]); scanf("%d", &keysList[3]); 10 11 12 13 scanf ("%d", &itemsList[0]); scanf ("%d", &itemsList[1]); scanf("%d", &itemsList[2]); scanf ("%d", &itemsList[3]); 14 15 16 17 18 19 /* Your code goes here */ 20 21 printf("\n"); 22 23 return 0; 24 }arrow_forward
- Lab Goal : This lab was designed to teach you more about list processing and algorithms.Lab Description : Write a program that will search through a list to find the smallest number and the largest number. The program will return the average the largest and smallest numbers. You must combine variables, ifs, and a loop to create a working method. There will always be at least one item in the list.arrow_forwardCreate a Flowchart for this code. import random #Define a function to pick 5 numbers from 1 to 38 def getNJCash5lottery_numbers(): #Return the list return random.sample(range(1, 39), 5) def playNJCash5lottery(): #Call the method and assign the list to variable lottery_number = getNJCash5lottery_numbers() print("These are the cash 5 numbers."), #Iterate over list elements for number in lottery_number: #Print the number on one line print(number) #Define a function def main(): while(True): #Call the method to print the list elements playNJCash5lottery() #Prompt the user if they want to play again decide = input("\nDo you want to play again? Yes/No : ") #If they entered "no " or "No" if decide.lower() == "no": #Exit break #Call the "main()" function if __name__ == "__main__": main()arrow_forwardGiven two ArrayLists: list1=[10,20,30], and list2=[40,50], what is the content of the list1 after executing the following statement: list1.addAll(list2) a. [40, 50] b. [10, 20, 30] c. [10, 40, 50, 20, 30] d. [10, 20, 30, 40, 50]arrow_forward
- Turn this into a flowchart/pseudo code. //This is where the functions go void insertfront(int data);void insert(int data);void display();void deletedata(int data);void reverselist();void searchdata(int data);void swap();void datasort();void deleteList(); #include <iostream>#include <stdlib.h>using namespace std; struct Node {int data;struct Node *next;}; struct Node* head = NULL;struct Node* rhead = NULL;int count1; //insert in front for reversedlistvoid insertfront(int data){Node* new_node = (Node*) malloc(sizeof(Node)); new_node->data = data; new_node->next = rhead; rhead=new_node;}//insert at endvoid insert(int new_data){Node* ptr;ptr = head;Node* new_node = (Node*) malloc(sizeof(Node)); new_node->data = new_data; new_node->next = NULL;if (head == NULL) { head = new_node; } else{while (ptr->next!= NULL) { ptr = ptr->next;}ptr->next=new_node;}count1++;}//display listvoid display() {struct Node* ptr;ptr = head;if(head==NULL){cout<<"Sorry the list…arrow_forwardID: A Name: Multiple Response Identify one or more choices that best complete the statement or answer the question. 10. The following code segment is intended to remove all duplicate elements in the list myList. The procedure does not work as intended. jt LENGTH(myList) REPEAT UNTIL(j = 1) %3D } IF(myList[j] = myList[j - 1]) %3D } REMOVE (myList, j) { j+j-1 { For which of the following contents of myList will the procedure NOT produce the intended results? a. [30, 30, 30, 10, 20, 20] b. [10, 10, 20, 20, 10, 10] c. [50, 50, 50, 50, 50, 50] d. [30, 50, 40, 10, 20, 40]arrow_forward#Hard-Coded board1_list = [['*','*','*'],['*','+','*'],['*','*','*']]print_board(board1_list)print() #just for a spacer lineboard2_list = [['*',' ',' ','*'], ['*',' ',' ','*'], ['*',' ',' ','*'], ['*',' ',' ','*']]print_board(board2_list)print() #just for a spacer lineboard3_list = [['*',' ','*',' ','*'], [' ','*',' ','*',' '], [' ',' ',' ',' ',' '], [' ','+',' ','+',' '], ['+',' ','+',' ','+']]print_board(board3_list)arrow_forward
- | Which data structure to use? Suppose you need to store a list of elements, if the number of elements in the program is fixed, what data structure should you use? (array, ArrayList, or LinkedList) If you have to add or delete the elements at the beginning of a list, should you use ArrayList or LinkedList? If most of operations on a list involve retrieving an element at a given index, should you use ArrayList or LinkedList?arrow_forwardPython write a program in python that plays the game of Hangman. When the user plays Hangman, the computer first selects a secret word at random from a list built into the program. The program then prints out a row of dashes asks the user to guess a letter. If the user guesses a letter that is in the word, the word is redisplayed with all instances of that letter shown in the correct positions, along with any letters correctly guessed on previous turns. If the letter does not appear in the word, the user is charged with an incorrect guess. The user keeps guessing letters until either: * the user has correctly guessed all the letters in the word or * the user has made eight incorrect guesses. one for each letter in the secret word and Hangman comes from the fact that incorrect guesses are recorded by drawing an evolving picture of the user being hanged at a scaffold. For each incorrect guess, a new part of a stick-figure body the head, then the body, then each arm, each leg, and finally…arrow_forwardLists and strings: Perform the following using the list and string defined below: Mylist = [“orange”,”banana”,”apple”,”grape”] Mystring = “314-800-2346” What does Mylist[2] equal? What does Mystring[2] equal? What does the len(Mylist) equal? What does len(Mystring) equal? Write a for loop that will display the strings in Mylist from last to first. Write a line of code that appends “pear” to Mylistarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT