Write a Java program to implement a singly linked list where each node contains one integer...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a Java program to implement a singly linked list where each node contains one integer value. Ask the user about the number of nodes to be inserted. Take that number of elements and their positions (except the first element) from the user and insert the elements in the linked list in their appropriate positions. Then print the list. Duplicate values are allowed. Now take an element from the user and remove every occurrence of that element from the list and print the list's remaining elements. Consider all possible cases of insertion and deletion. You can use the Java Scanner class to take inputs from the user. Do not use any in-built Java method. The sample input/ output is given below: (25 points) Sample input/ output: (User's inputs are shown in bold) Enter the number of nodes: 5 Enter an element: 2 Enter an element: 12 Enter the position: 5 Wrong position! Enter an element: 12 Enter the position: 1 Enter an element: 3 Enter the position: 2 Enter an element: 1 Enter the position: 4 Enter an element: 3 Enter the position: 4 The elements of the linked list: 12 3 231 Enter a number to delete: 4 Number is not found! Enter a number to delete: 3 The elements of the linked list: 12 21 Write a Java program to implement a singly linked list where each node contains one integer value. Ask the user about the number of nodes to be inserted. Take that number of elements and their positions (except the first element) from the user and insert the elements in the linked list in their appropriate positions. Then print the list. Duplicate values are allowed. Now take an element from the user and remove every occurrence of that element from the list and print the list's remaining elements. Consider all possible cases of insertion and deletion. You can use the Java Scanner class to take inputs from the user. Do not use any in-built Java method. The sample input/ output is given below: (25 points) Sample input/ output: (User's inputs are shown in bold) Enter the number of nodes: 5 Enter an element: 2 Enter an element: 12 Enter the position: 5 Wrong position! Enter an element: 12 Enter the position: 1 Enter an element: 3 Enter the position: 2 Enter an element: 1 Enter the position: 4 Enter an element: 3 Enter the position: 4 The elements of the linked list: 12 3 231 Enter a number to delete: 4 Number is not found! Enter a number to delete: 3 The elements of the linked list: 12 21
Expert Answer:
Answer rating: 100% (QA)
LinkedList class LinkedList instance variables private Node head private int size inner Node class class Node int num Node next Nodeint num thisnum nu... View the full answer
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Posted Date:
Students also viewed these programming questions
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
Prepare adjusting journal entries, as needed, considering the account balances excerpted from the unadjusted trial balance and the adjustment data. A. depreciation on fixed assets, $ 8,500 B....
-
A researcher records the following data for each of three groups. What is the value of the F statistic? Explain your answer. GroupA Group B Group C 10 13 12 10
-
A citys population is 1000 and growing at 5% a year. (a) Find a formula for the population at time t years from now assuming that the 5% per year is an: (i) Annual rate (ii) Continuous annual rate...
-
Go to the St. Louis Federal Reserve FRED database, and find data on real GDP (GDPC1), potential GDP (GDPPOT), and the unemployment rate (UNRATE) from 1960 to the most recent period. For the...
-
You are provided with the following information for Koetteritz Inc. for the month ended June 30, 2017. Koetteritz uses the periodic method for inventory. Instructions (a) Calculate (i) Ending...
-
The buyer at Ajax Co. is responsible for maintaining inventory of a key component which is used in the firm's manufacturing process throughout the entire 52-week year. The annual demand is 12,000...
-
The porosity P of a wall varies linearly along its thickness according to P= b+cx, where b and c are constant. The wall thickness is L and its area is A. The coolant flow rate is m. The two surfaces...
-
Does culture or gender have something to do with how employees respond to empowerment? Please give examples.
-
At the beginning of Year 3 Randall Company had a $13,600 balance in its accounts receivable account and a $1,175 balance in allowance for doubtful accounts. During Year 3, Randall experienced the...
-
How does society strategically combat cybercrime? How effective are employee training and professional development in combatting cybercrime within an organization? If you were in a leadership role...
-
How does society define Deviance. What factors would contribute to someone behaving in a "deviant " manner?
-
How does work-life balance impact an audience? In other words, how is the issue (work-life balance) relevant to members of the audience? Why should the audience care about the response to the...
-
The purpose of presenting comparative information in the transition to IFRS is: (a) to ensure that the information is a faithful representation. (b) to be in accordance with the Sarbanes-Oxley Act....
-
In Exercises 516, find the focus and directrix of the parabola with the given equation. Then graph the parabola. y 2 = 4x
-
Write classes that implement the general tree class declarations of Figure 6.2 using the dynamic left-child/right-sibling representation described in Section 6.3 .4. /** General tree ADT */ interface...
-
Prove (using induction) that the recurrence T(n) = T(n 1) + n; T(1) = 1 has as its closed-form solution T(n) = n(n + 1)/2.
-
Prove by contradiction that the number of primes is infinite.
-
In the case considered in the question (14), show what the trajectory corresponds to in case the magnitude of acceleration is \(a=2 k \sqrt{1+\frac{t}{T}}\), where \(T=\) cost. Question 14 A particle...
-
The position vector along a trajectory expressed in terms of the scalar distance \(s\) from the origin is given by the relation \(\mathbf{r}=\mathbf{a} s^{2}+\mathbf{b} s+\mathbf{c}\), with the...
-
A particle is constrained to move on a circular guideway of radius \(R=3.00 \mathrm{~m}\), on which it can slide without friction, according to the motion equation law \(s(t)=k t^{3}\), with \(k=2.0...
Study smarter with the SolutionInn App