Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 12, Problem 10E

Explanation of Solution

Modified code for “StringLinkedList” class:

The modified code for “StringLinkedList” class is given below:

Filename: “ListNode.java”

//Define "ListNode" class

public class ListNode

{

/* This class is same as the code in Listing 12.4 of textbook */

}

Filename: “StringLinkedList.java”

/* This class is same as the code in Listing 12.5 of textbook */

//Define "StringLinkedList" class

public class StringLinkedList

{

  private ListNode head;

  /* Create constructor for "StringLinkedList" class*/

  public StringLinkedList()

  {

  head = null;

  }

  /* Displays the data on the list.*/

  public void showList()

  {

  ListNode position = head;

  while (position != null)

  {

  System.out.println(position.getData());

  position = position.getLink();

  }

  }

  /* Returns the number of nodes on the list.*/

  public int length()

  {

  int count = 0;

  ListNode position = head;

  while (position != null)

  {

  count++;

  position = position.getLink();

  }

  return count;

  }

/* Adds a node containing the data addData at the start of the list.*/

  public void addANodeToStart(String addData)

  {

  head = new ListNode(addData, head);

  }

/* Method definition for add a node at the end of list */

public void addANodeToEnd(String addData)

{

  /* If head is null or empty, then */

  if(head == null)

  //Add node to the front

  addANodeToStart(addData);

  //Otherwise

  else

  {

  /* Assign "s" to "head" */

  ListNode s = head;

  //Compute the last node in the list

  while(s.getLink() != null)

  {

  s = s.getLink();

  }

  // Add in the node

  ListNode c = new ListNode(addData, null);

  s.setLink(c);

  }

  }

  /* Deletes the first node on the list.*/

  public void deleteHeadNode()

  {

  if (head != null)

  head = head.getLink();

  else

  {

System.out.println("Deleting from an empty list.");

System.exit(0);

}

}

/* Method definition for deletes the last node on the list */

public void deleteLastNode()

  {

  /* If head is null or empty, then */

  if (head == null)

  {

  //Display given message

System.out.println("Deleting from an empty list.");

System.exit(0);

}

  /* If "head.getLink()" is null, then */

  else if (head.getLink() == null)

  {

/* Delete first node in the list by calling method "deleteHeadNode" */

deleteHeadNode();

}

  //Otherwise

  else

  {

  //Set "s" to "head"

  ListNode s = head;

  //Look for the node before the final node

  while(s.getLink().getLink() != null)

  s = s.getLink();

  //Unlink the last node

  s.setLink(null);

  }

  }

  /* Sees whether target is on the list.*/

  public boolean onList(String target)

  {

  return find(target) != null;

  }

  // Returns a reference to the first node containing the

// target data. If target is not on the list, returns null.

private ListNode find(String target)

{

boolean found = false;

ListNode position = head;

while ((position != null) && !found)

{

  String dataAtPosition = position.getData();

  if (dataAtPosition.equals(target))

  found = true;

  else

  position = position.getLink();

  }

  return position;

  }

}

Modified Filename: “StringLinkedListDemo.java”

//Define "StringLinkedListDemo" class

public class Main

{

  //Define main function

  public static void main(String[] args)

  {

//Create object "list" from "StringLinkedList" class

  StringLinkedList list = new StringLinkedList();

/* Add three node to list by calling the method "addANodeToStart" */

list...

Blurred answer
Students have asked these similar questions
Create an original network topology consisting of at least seven routers and twelve links, assigning arbitrary positive weights to each link. Using this topology, apply Dijkstra's Link-State Algorithm to compute the shortest paths from a source router of your choice to all other routers in the network. Your topology must be entirely your own design and should not resemble any examples from the textbook, lecture slides, or other students' work. Al-generated topologies are not permitted. Create a PowerPoint presentation that follows the format and style of slides 11 to 23 from Lecture Slide Set 06 (LS06). You should copy those slides and make any necessary changes, additions, or deletions to reflect your own topology, shortest-path calculations, and update tables. Do not alter the original slide style, layout, or formatting.
Create an original network topology consisting of at least seven routers and twelve links, assigning arbitrary positive weights to each link. Using this topology, apply Dijkstra's Link-State Algorithm to compute the shortest paths from a source router of your choice to all other routers in the network. Your topology must be entirely your own design and should not resemble any examples from the textbook, lecture slides, or other students' work. Al-generated topologies are not permitted. Create
x3003 x3008 1110 0000 0000 1100 1110 0010 0001 0000 0101 0100 1010 0000 x3004 0010 0100 0001 0011 x3005 0110 0110 0000 0000 X3006 0110 1000 0100 0000 x3007 0001 0110 1100 0100 0111 0110 0000 What does the following LC-3 program do? Trace Step by Step, SHOW ALL YOUR WORK. x3001 x3002 0000 x3009 0001 0000 0010 0001 X300A 0001 0010 0110 0001 x300B 0001 0100 1011 1111 x300C 0000 0011 1111 1000 X300D 1111 0000 0010 0101 x300E 0000 0000 0000 0101 x300F 0000 0000 0000 0100 x3010 0000 0000 0000 0011 x3011 0000 0000 0000 0110 x3012 0000 0000 0000 0010 x3013 x3014 0000 0000 0000 0000 0000 0100 0000 0111 x3015 0000 0000 0000 0110 x3016 0000 0000 0000 1000 x3017 0000 0000 0000 0111 x3018 0000 0000 0000 0101

Chapter 12 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Calculating total series of numbers: In order to calculate the total of the given numbers, it is necessary to h...

Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)

Fill in the blanks.

Modern Database Management

The Speed of Sound Program Plan: Import the required packages. Declare the class “Main”. Declare the “main ()” ...

Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)

By listing the types of measurements that form the basis of traditional plane surveying.

Elementary Surveying: An Introduction To Geomatics (15th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY