Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 20, Problem 1PC
Program Plan Intro
Generic Linked Lists
Program Plan:
- Import required package.
- Define “GenericLinkedList” class.
- Define “Node” class.
- Declare a value of a list element in generic type.
- Declare next node in the list using “Node” class.
- Parameterized constructor for “Node” class with two parameters.
- Parameterized constructor for “Node” class with one parameter.
- Declare variable for head of the list.
- Declare variable for last element of list.
- Define the method “clear()” which is used to remove all elements from the list.
- Initializes the index to “0”.
- If the head of the list is not “null”, then set temp node to head of the list and performs “while” loop.
- Remove an element in the list one by one using “while” loop.
- Set “temp_node” to next value of “temp_node”.
- Remove the given element by calling the method “remove”.
- Remove an element in the list one by one using “while” loop.
- Define the method “get()” which is used to return the value at given index in the list.
- Initializes “idx” to “0”.
- If the head of the list is not null, then
- Set head of list to “tempValue”.
- Check condition using “while” loop.
- If “idx” equals to given “index”, then return the element at given position.
- Otherwise, increment the value of “idx” and set “tempValue” to next value of “tempValue”
- Define the method “set()” which is used to replace the value at the specified position with the specified element and also return the previous element.
- Initializes “idx” to “0”.
- Check condition using “while” loop.
- If “idx” equals to given “index”, then replace the element at given position and return the previous element.
- Otherwise, increment the value of “idx” and set “tempValue” to next value of “tempValue”.
- Define the method “isEmpty()” which is used to compute whether list is in empty or not.
- Define the method “size()” which is used to compute the size of list.
- Define the method “add()” which is used to add an element to the list.
- Define the method “remove” which is used to remove an element from the list.
- Define main function.
- Create object for “Scanner” class.
- Create object “list” in “double” type using “GenericLinkedList” class.
- Add elements to “list” using “add()” method.
- Display the elements in list.
- To test the “set” method.
- Initializes the index to “-1”.
- Declare variable in “double” type.
- Performs “do-while” loop.
- Read index string from user.
- Convert the string value in integer.
- If the user entered index is less than “0” or greater than or equal to “size”, then display an error message.
- Read the new element for given index.
- Convert the string to double.
- Replace the new element in the place of old element by calling the method “set”.
- Display the old element in the given index.
- Display the list after calling “set” method.
-
- To test the “get” method.
- Initializes the index to “-1”.
- Performs “do-while” loop.
- Read the index from user.
- Convert the string to integer.
- If the user entered index is less than “0” or greater than or equal to “size”, then display an error message
- Display the element at given index by calling the method “get()”.
- Clear all the elements in the list by calling the method “clear()”.
- Display the size of list after clearing the list by calling “size()” method.
- To test the “get” method.
-
- Define “Node” class.
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 20 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 20.1 - Prob. 20.1CPCh. 20.1 - Prob. 20.2CPCh. 20.3 - Prob. 20.4CPCh. 20 - A list is a collection that _____. a. associates...Ch. 20 - Prob. 2MCCh. 20 - Prob. 3MCCh. 20 - Prob. 4MCCh. 20 - Prob. 5MCCh. 20 - Prob. 6MCCh. 20 - Prob. 7MC
Ch. 20 - Prob. 11TFCh. 20 - Prob. 12TFCh. 20 - Prob. 13TFCh. 20 - Prob. 14TFCh. 20 - Prob. 15TFCh. 20 - Prob. 16TFCh. 20 - Prob. 17TFCh. 20 - Prob. 18TFCh. 20 - Prob. 29TFCh. 20 - Prob. 20TFCh. 20 - Prob. 1FTECh. 20 - Prob. 2FTECh. 20 - Prob. 3FTECh. 20 - Prob. 4FTECh. 20 - Prob. 5FTECh. 20 - Prob. 1AWCh. 20 - Prob. 2AWCh. 20 - Prob. 3AWCh. 20 - Prob. 4AWCh. 20 - Prob. 3SACh. 20 - Prob. 4SACh. 20 - Prob. 5SACh. 20 - Consult the online Java documentation and...Ch. 20 - Prob. 1PCCh. 20 - 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
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT