Question

In: Computer Science

Urgent! pls show all ways of how to make a deep copy of each elements in...

Urgent! pls show all ways of how to make a deep copy of each elements in a singly linked list (linear time)

(pls write code with explanation in java! Thanks in advance! )

Solutions

Expert Solution

Showing all ways of how to make a deep copy of each element in a singly linked list in java:

1. Using Hashmap to make a deep copy of the singly linked list by cloning every element of a linked list with next and random pointer:

we need to make a replica of this linked list, that simply means we need to create a deep copy of this LinkedList with difference reference head pointer for both the linked list:

let the singly linked list be:

During the iteration of the first node of the linked list, the hashmap will create a node with the same value. this node will be store as a value of hashmap and the original node reference will be store as a key of hashmap. suppose below is the hashmap:

where n1, n2, n3, and n4 are the copied linked list values copied linked list looks like:

Java code to make a deep copy of the singly linked list by cloning every element of a linked list with next and random pointer:

The output of code is as follow in terms of returning a copied linked list:

so this is how one can get copied LinkedList from the original linked list.

2. One can make a deep copy of a linked list using the override method, that is:

The output of the code is:

3. One can make a copy of the linked list element using the LinkedList clone() method:

The output of the code is as:

so this is some possible way of copy the data of LinkedList to other LinkedList.


Related Solutions

pls use deep clone method to make a deep copy of each elements in a singly...
pls use deep clone method to make a deep copy of each elements in a singly linked list. (show detailed code and explanation in java. thanks!)
I want to copy all the elements in f1() to f2() but in reverse order (C++)...
I want to copy all the elements in f1() to f2() but in reverse order (C++) this is my code: #include <iostream> #include <iomanip> using namespace std; const int R=10; const int C=10; int Array[R][C] ; ///////////////////////////////////// void f1(){ for(int i=0 ; i<R ; i++){    for(int j=0 ; j<C ; j++){ Array[i][j]= (rand () %100) + 1; } } for(int i=0 ; i<R ; i++){    for(int j=0 ; j<C ; j++){    cout<<"["<<i<<"]["<<j<<"]="<<setw(3)<<Array[i][j]<<" ";    } cout<<endl; }...
For each of the following situations, show how (if at all) the IS, MP, and AD...
For each of the following situations, show how (if at all) the IS, MP, and AD curves are affected. Show clearly any shifts or movements along the curves. If there is no change, just type “No change in …” a. A decrease in financial frictions b. An increase in the current inflation c. Firms become more optimistic about the future of the economy d. An autonomous monetary policy tightening occurs e. An increase in taxes and an autonomous easing of...
Short answer pls: . How do Vygotsky and Piaget differ in the ways they describe children’s’...
Short answer pls: . How do Vygotsky and Piaget differ in the ways they describe children’s’ learning (try to provide an example)? Describe one piece of evidence / data / example that suggests learning occurs during the prenatal period.
Pls attempt all parts for Upvote a) The median incomes of females in each state of...
Pls attempt all parts for Upvote a) The median incomes of females in each state of the United States, including the District of Columbia and Puerto Rico, are given in table #2.2.10 ("Median income of," 2013). Create a frequency distribution, relative frequency distribution, and cumulative frequency distribution using 7 classes. Table #2.2.10: Data of Median Income for Females $31,862 $40,550 $36,048 $30,752 $41,817 $40,236 $47,476 $40,500 $60,332 $33,823 $35,438 $37,242 $31,238 $39,150 $34,023 $33,745 $33,269 $32,684 $31,844 $34,599 $48,748 $46,185...
II. Show all of your work in each question. In parts (d), (e), and (g) make...
II. Show all of your work in each question. In parts (d), (e), and (g) make sure to set up your null and alternative hypotheses and write your conclusions. Also, please round your numbers to 2 decimal points. Write legibly and neatly. III. You can use p-value approach or critical-value approach in writing the conclusions of your hypotheses. A large firm employing tens of thousands of workers has been accused of discriminating against its female managers. The accusation is based...
Show all of your work in each question. In parts (d), (e), and (g) make sure...
Show all of your work in each question. In parts (d), (e), and (g) make sure to set up your null and alternative hypotheses and write your conclusions. Also, please round your numbers to 2 decimal points. Write legibly and neatly. You can use p-value approach or critical-value approach in writing the conclusions of your hypotheses. A large firm employing tens of thousands of workers has been accused of discriminating against its female managers. The accusation is based on a...
Read each question carefully, make sure to answer all questions are answered and show your work:...
Read each question carefully, make sure to answer all questions are answered and show your work: 5. Nast stores has derived the following consumer credit-scoring model after years of data collect Y=(0.20 x Employment) + (0.4 x Homeowner) + (0.3 x Cards) Employment = 1 if employed part-time, and 0 if unemployed Cards= 1 if presently has 1-5 credit cards, 0 otherwise Nast determines that a score of at least 0.70 indicates a very good credit risk, and it extends...
Show all work and answer steps in complete sentences pls list them ex. Step 1 underline...
Show all work and answer steps in complete sentences pls list them ex. Step 1 underline steps A psychologist wants to compare the group of people who exercise regularly and the group of people who do not exercise regularly on the level of stress. She took a sample of 8 people from each population. These numbers indicate the participants’ stress levels. Can she conclude that there is a difference between two groups on the level of stress? Conduct four steps...
Use Minitab to answer the questions. Make sure to copy all output from the Minitab: The...
Use Minitab to answer the questions. Make sure to copy all output from the Minitab: The U.S. Bureau of Labor Statistics publishes a variety of unemployment statistics, including the number of individuals who are unemployed and the mean length of time the individuals have been unemployed. For November 1998, the Bureau of Labor Statistics reported that the national mean length of time of unemployment was 14.5 weeks. The mayor of Chicago has requested the study on the status of unemployment...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT