EBK STARTING OUT W/JAVA:...DATA...
EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
bartleby

Concept explainers

Question
Book Icon
Chapter 19, Problem 2PC
Program Plan Intro

Linked List Sorting and Reversing

Program Plan:

For filename: Modified “LinkedList1.java”

  • In this class, additionally need to add two methods “sort()” and “reverse()”.
  • Define the method “sort()” which is used to sort the elements in the list by alphabetical order.
    • Create two variables “current_node” and “index_value” using “Node” class and this variable set to “null”.
    • Declare a string variable “temp_value”.
    • Check whether list is empty. If the list is empty, then returns nothing.
    • Otherwise,
      • Check condition using “for” loop. That is the current node will point to first.
        • Check the condition using “for” loop that is for index value will point to next node of current node.
          • If data in the “current_node” is greater than the data in “index_value”, then swap the data of “current_node” and “index_index”.
  • Define the method “reverse()” which is used to reverse the elements in the list.
    • Create a list “rev_list” and set it to “null”.
    • Performs “while” loop. This loop will perform up to the first node equals to “null”.
      • Set a reference “ref” to first node.
      • Set “first” to next first node.
      • Set next node to “rev_list”.
      • Set the “rev_list” to reference “ref”.
    • Make the list “rev_list” as the new list.

For filename: “LinkedList1Demo.java”:

  • Import required package.
  • Define “LinkedList1Demo” class.
    • Create an instance for “LinkedList1” class, text area, command text field, and result text field.
    • Define constructor for “LinkedList1Demo()” class.
      • Create instance.
      • Create a panel for “Command Result” text field.
      • Create a label for command result.
      • Place the text area in center of the frame.
      • Create a panel and label for “Command” text field.
      • Set up the frame.
    • Define private class “commandTextListener” that reply to the user entered command.
      • Define “actionPerformed” class.
        • Read the command from the command text field.
        • Create an object for “Scanner” class.
        • Read command from user.
        • Check the user entered command using “switch” statement.
          • If the user entered command is “sort”, then,
            • Sort the linked list “new_list” by calling the method “sort()”.
            • Displays lists in alphabetical order.
            • Assign a status message for the “sort” command was finished.
            • Displays status message to “Command Result” text field.
          • If the user entered command is “reverse”, then
            • Reverse the linked list “new_list” by calling the method “reverse()”.
            • Prints the reversed list.
            • Assign a status message for the “reverse” command was finished.
            • Displays status message to “Command Result” text field.
          • If the user entered command is “add”, then
            • Check condition. If it is true, then
              • Read index and string element from user.
              • Add that index and its element to linked list “new_list” by calling the method “add”.
            • Otherwise,
              • Read string element from user.
              • Add string element to the list “new_list” by calling the method “add”.
            • Display the added string elements.
          • If the user entered command is “remove”, then
            • Check condition. If it is true, then
              • Read an index from user.
              • Remove an element at given index.
              • Display the removed element at given index to “Command Result” text field.
            • Otherwise,
              • Read an element from the list.
              • Obtain the Boolean result.
              • Convert the Boolean into string.
              • Display the Boolean result to “Command Result” text field.
            • Displays string elements in the list
          • If the user entered command is “isEmpty”, then
            • Check the given list is empty or not by calling the method “isEmpty” and store the result in “result_text3”.
            • Display the result to “Command Result” text field.
          • If the user entered command is “size”, then
            • Compute the size of list “new_list” by calling the method “size()” and store the result in “result_text4”.
            • Display the result to “Command Result” text field.
    • Define main function.
      • The instance of “LinkedList1Demo” class displays its window.

Blurred answer
Students have asked these similar questions
Problem Statement You are working as a Devops Administrator. Y ou’ve been t asked to deploy a multi - tier application on Kubernetes Cluster. The application is a NodeJS application available on Docker Hub with the following name: d evopsedu/emp loyee This Node JS application works with a mongo database. MongoDB image is available on D ockerHub with the following name: m ongo You are required to deploy this application on Kubernetes: • NodeJS is available on port 8888 in the container and will be reaching out to por t 27017 for mongo database connection • MongoDB will be accepting connections on port 27017 You must deploy this application using the CL I . Once your application is up and running, ensure you can add an employee from the NodeJS application and verify by going to Get Employee page and retrieving your input. Hint: Name the Mongo DB Service and deployment, specifically as “mongo”.
I need help in server client project. It is around 1200 lines of code in both . I want to meet with the expert online because it is complicated. I want the server send a menu to the client and the client enters his choice and keep on this until the client chooses to exit . the problem is not in the connection itself as far as I know.I tried while loops but did not work. please help its emergent
I need help in my server client in C language
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning