Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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”.
- Check the condition using “for” loop that is for index value will point to next node of current node.
- Check condition using “for” loop. That is the current node will point to first.
- 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.
- Check condition. If it is true, then
- 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
- Check condition. If it is true, then
- 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 “actionPerformed” class.
- Define main function.
- The instance of “LinkedList1Demo” class displays its window.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
We are considering the RSA encryption scheme. The involved numbers are small, so the communication is insecure. Alice's public key (n,public_key) is (247,7).
A code breaker manages to factories 247 = 13 x 19
Determine Alice's secret key.
To solve the problem, you need not use the extended Euclid algorithm, but you may assume that her private key is one of the following numbers 31,35,55,59,77,89.
Consider the following Turing Machine (TM). Does the TM halt if it begins on the empty tape? If it halts, after how many steps? Does the TM halt if it begins on a tape that contains a single letter A followed by blanks? Justify your answer.
Pllleasassseee ssiiirrrr soolveee thissssss questionnnnnnn
Chapter 19 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 19.1 - Prob. 19.1CPCh. 19.1 - Prob. 19.2CPCh. 19.3 - Prob. 19.4CPCh. 19 - A list is a collection that _____. a. associates...Ch. 19 - Prob. 2MCCh. 19 - Prob. 3MCCh. 19 - Prob. 4MCCh. 19 - Prob. 5MCCh. 19 - Prob. 6MCCh. 19 - Prob. 7MC
Ch. 19 - Prob. 11TFCh. 19 - Prob. 12TFCh. 19 - Prob. 13TFCh. 19 - Prob. 14TFCh. 19 - Prob. 15TFCh. 19 - Prob. 16TFCh. 19 - Prob. 17TFCh. 19 - Prob. 18TFCh. 19 - Prob. 19TFCh. 19 - Prob. 20TFCh. 19 - Prob. 1FTECh. 19 - Prob. 2FTECh. 19 - Prob. 3FTECh. 19 - Prob. 4FTECh. 19 - Prob. 5FTECh. 19 - Prob. 1AWCh. 19 - Prob. 2AWCh. 19 - Prob. 3AWCh. 19 - Prob. 4AWCh. 19 - Prob. 3SACh. 19 - Prob. 4SACh. 19 - Prob. 5SACh. 19 - Consult the online Java documentation and...Ch. 19 - Prob. 1PCCh. 19 - Prob. 2PC
Knowledge Booster
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
- 4. def modify_data(x, my_list): X = X + 1 my_list.append(x) print(f"Inside the function: x = {x}, my_list = {my_list}") num = 5 numbers = [1, 2, 3] modify_data(num, numbers) print(f"Outside the function: num = {num}, my_list = {numbers}") Classe Classe that lin Thus, A pro is ref inter Ever dict The The output: Inside the function:? Outside the function:?arrow_forwardpython Tasks 5 • Task 1: Building a Library Management system. Write a Book class and a function to filter books by publication year. • Task 2: Create a Person class with name and age attributes, and calculate the average age of a list of people Task 3: Building a Movie Collection system. Each movie has a title, a genre, and a rating. Write a function to filter movies based on a minimum rating. ⚫ Task 4: Find Young Animals. Create an Animal class with name, species, and age attributes, and track the animals' ages to know which ones are still young. • Task 5(homework): In a store's inventory system, you want to apply discounts to products and filter those with prices above a specified amount. 27/04/1446arrow_forwardOf the five primary components of an information system (hardware, software, data, people, process), which do you think is the most important to the success of a business organization? Part A - Define each primary component of the information system. Part B - Include your perspective on why your selection is most important. Part C - Provide an example from your personal experience to support your answer.arrow_forward
- Management Information Systemsarrow_forwardQ2/find the transfer function C/R for the system shown in the figure Re དarrow_forwardPlease original work select a topic related to architectures or infrastructures (Data Lakehouse Architecture). Discussing how you would implement your chosen topic in a data warehouse project Please cite in text references and add weblinksarrow_forward
- Please original work What topic would be related to architectures or infrastructures. How you would implement your chosen topic in a data warehouse project. Please cite in text references and add weblinksarrow_forwardWhat is cloud computing and why do we use it? Give one of your friends with your answer.arrow_forwardWhat are triggers and how do you invoke them on demand? Give one reference with your answer.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning