SlideShare a Scribd company logo
1 of 5
Download to read offline
Problem: Describe an algorithm for concatenating two singly linked lists L and M, into a single
list L that contains all the nodes of L followed by all the nodes of M. Modify the
SinglyLinkedList class to contain the method:
public void concatenate(SinglyLinkedList other) { ... }
PLEASE PLEASE USE THE CODE BELOW..... THANK YOU
public class SinglyLinkedList<E> implements Cloneable {
//---------------- nested Node class ----------------
/**
* Node of a singly linked list, which stores a reference to its
* element and to the subsequent node in the list (or null if this
* is the last node).
*/
private static class Node<E> {
/** The element stored at this node */
private E element; // reference to the element stored at this node
/** A reference to the subsequent node in the list */
private Node<E> next; // reference to the subsequent node in the list
/**
* Creates a node with the given element and next node.
*
* @param e the element to be stored
* @param n reference to a node that should follow the new node
*/
public Node(E e, Node<E> n) {
element = e;
next = n;
}
// Accessor methods
/**
* Returns the element stored at the node.
* @return the element stored at the node
*/
public E getElement() { return element; }
/**
* Returns the node that follows this one (or null if no such node).
* @return the following node
*/
public Node<E> getNext() { return next; }
// Modifier methods
/**
* Sets the node's next reference to point to Node n.
* @param n the node that should follow this one
*/
public void setNext(Node<E> n) { next = n; }
} //----------- end of nested Node class -----------
// instance variables of the SinglyLinkedList
/** The head node of the list */
private Node<E> head = null; // head node of the list (or null if empty)
/** The last node of the list */
private Node<E> tail = null; // last node of the list (or null if empty)
/** Number of nodes in the list */
private int size = 0; // number of nodes in the list
/** Constructs an initially empty list. */
public SinglyLinkedList() { } // constructs an initially empty list
// access methods
/**
* Returns the number of elements in the linked list.
* @return number of elements in the linked list
*/
public int size() { return size; }
/**
* Tests whether the linked list is empty.
* @return true if the linked list is empty, false otherwise
*/
public boolean isEmpty() { return size == 0; }
/**
* Returns (but does not remove) the first element of the list
* @return element at the front of the list (or null if empty)
*/
public E first() { // returns (but does not remove) the first element
if (isEmpty()) return null;
return head.getElement();
}
/**
* Returns (but does not remove) the last element of the list.
* @return element at the end of the list (or null if empty)
*/
public E last() { // returns (but does not remove) the last element
if (isEmpty()) return null;
return tail.getElement();
}
// update methods
/**
* Adds an element to the front of the list.
* @param e the new element to add
*/
public void addFirst(E e) { // adds element e to the front of the list
head = new Node<>(e, head); // create and link a new node
if (size == 0)
tail = head; // special case: new node becomes tail also
size++;
}
/**
* Adds an element to the end of the list.
* @param e the new element to add
*/
public void addLast(E e) { // adds element e to the end of the list
Node<E> newest = new Node<>(e, null); // node will eventually be the tail
if (isEmpty())
head = newest; // special case: previously empty list
else
tail.setNext(newest); // new node after existing tail
tail = newest; // new node becomes the tail
size++;
}
/**
* Removes and returns the first element of the list.
* @return the removed element (or null if empty)
*/
public E removeFirst() { // removes and returns the first element
if (isEmpty()) return null; // nothing to remove
E answer = head.getElement();
head = head.getNext(); // will become null if list had only one node
size--;
if (size == 0)
tail = null; // special case as list is now empty
return answer;
}
@SuppressWarnings({"unchecked"})
public boolean equals(Object o) {
if (o == null) return false;
if (getClass() != o.getClass()) return false;
SinglyLinkedList other = (SinglyLinkedList) o; // use nonparameterized type
if (size != other.size) return false;
Node walkA = head; // traverse the primary list
Node walkB = other.head; // traverse the secondary list
while (walkA != null) {
if (!walkA.getElement().equals(walkB.getElement())) return false; //mismatch
walkA = walkA.getNext();
walkB = walkB.getNext();
}
return true; // if we reach this, everything matched successfully
}
@SuppressWarnings({"unchecked"})
public SinglyLinkedList<E> clone() throws CloneNotSupportedException {
// always use inherited Object.clone() to create the initial copy
SinglyLinkedList<E> other = (SinglyLinkedList<E>) super.clone(); // safe cast
if (size > 0) { // we need independent chain of nodes
other.head = new Node<>(head.getElement(), null);
Node<E> walk = head.getNext(); // walk through remainder of original list
Node<E> otherTail = other.head; // remember most recently created node
while (walk != null) { // make a new node storing same element
Node<E> newest = new Node<>(walk.getElement(), null);
otherTail.setNext(newest); // link previous node to this one
otherTail = newest;
walk = walk.getNext();
}
}
return other;
}
public int hashCode() {
int h = 0;
for (Node walk=head; walk != null; walk = walk.getNext()) {
h ^= walk.getElement().hashCode(); // bitwise exclusive-or with element's code
h = (h << 5) | (h >>> 27); // 5-bit cyclic shift of composite code
}
return h;
}
/**
* Produces a string representation of the contents of the list.
* This exists for debugging purposes only.
*/
public String toString() {
StringBuilder sb = new StringBuilder("(");
Node<E> walk = head;
while (walk != null) {
sb.append(walk.getElement());
if (walk != tail)
sb.append(", ");
walk = walk.getNext();
}
sb.append(")");
return sb.toString();
}
public void concatenate(SinglyLinkedList<E> other) {
............. TYPE CODE HERE.........
}
}
}

More Related Content

Similar to Problem- Describe an algorithm for concatenating two singly linked lis.pdf

Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfinfo430661
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfConint29
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdfdeepakangel
 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfarcellzone
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfclimatecontrolsv
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfsauravmanwanicp
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdffantasiatheoutofthef
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdfsudhirchourasia86
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
here is the starter code public class LinkedListPracticeLab.pdf
here is the starter code public class LinkedListPracticeLab.pdfhere is the starter code public class LinkedListPracticeLab.pdf
here is the starter code public class LinkedListPracticeLab.pdfgeetakannupillai1
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
 
I have been tasked to write a code for a Singly Linked list that inc.pdf
I have been tasked to write a code for a Singly Linked list that inc.pdfI have been tasked to write a code for a Singly Linked list that inc.pdf
I have been tasked to write a code for a Singly Linked list that inc.pdfarkmuzikllc
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfhadpadrrajeshh
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdffacevenky
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdfAdrianEBJKingr
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructuresmartha leon
 

Similar to Problem- Describe an algorithm for concatenating two singly linked lis.pdf (20)

Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdf
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
here is the starter code public class LinkedListPracticeLab.pdf
here is the starter code public class LinkedListPracticeLab.pdfhere is the starter code public class LinkedListPracticeLab.pdf
here is the starter code public class LinkedListPracticeLab.pdf
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
I have been tasked to write a code for a Singly Linked list that inc.pdf
I have been tasked to write a code for a Singly Linked list that inc.pdfI have been tasked to write a code for a Singly Linked list that inc.pdf
I have been tasked to write a code for a Singly Linked list that inc.pdf
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructures
 

More from kingsandqueens3

products apperar below Assume that sulficient time is available on the.pdf
products apperar below Assume that sulficient time is available on the.pdfproducts apperar below Assume that sulficient time is available on the.pdf
products apperar below Assume that sulficient time is available on the.pdfkingsandqueens3
 
Procedure for Activity 1-2- Applying Directional Terms Part 1 Procedur.pdf
Procedure for Activity 1-2- Applying Directional Terms Part 1 Procedur.pdfProcedure for Activity 1-2- Applying Directional Terms Part 1 Procedur.pdf
Procedure for Activity 1-2- Applying Directional Terms Part 1 Procedur.pdfkingsandqueens3
 
process- and conversion costs are added everly during the peocess- Spo.pdf
process- and conversion costs are added everly during the peocess- Spo.pdfprocess- and conversion costs are added everly during the peocess- Spo.pdf
process- and conversion costs are added everly during the peocess- Spo.pdfkingsandqueens3
 
Process capability A- exists when CPK is less than 1-0- B- means that.pdf
Process capability A- exists when CPK is less than 1-0- B- means that.pdfProcess capability A- exists when CPK is less than 1-0- B- means that.pdf
Process capability A- exists when CPK is less than 1-0- B- means that.pdfkingsandqueens3
 
Problem VII - Debt and Stock Investments Cam Inc- has decided to inves.pdf
Problem VII - Debt and Stock Investments Cam Inc- has decided to inves.pdfProblem VII - Debt and Stock Investments Cam Inc- has decided to inves.pdf
Problem VII - Debt and Stock Investments Cam Inc- has decided to inves.pdfkingsandqueens3
 
Problem V-Fair Value Adiustment HQ Inc- has the following trading port.pdf
Problem V-Fair Value Adiustment HQ Inc- has the following trading port.pdfProblem V-Fair Value Adiustment HQ Inc- has the following trading port.pdf
Problem V-Fair Value Adiustment HQ Inc- has the following trading port.pdfkingsandqueens3
 
Problem Statement Several students in our college struggle with academ.pdf
Problem Statement Several students in our college struggle with academ.pdfProblem Statement Several students in our college struggle with academ.pdf
Problem Statement Several students in our college struggle with academ.pdfkingsandqueens3
 
Problem Gross Estate For each type of decedent- compute for the gross.pdf
Problem Gross Estate For each type of decedent- compute for the gross.pdfProblem Gross Estate For each type of decedent- compute for the gross.pdf
Problem Gross Estate For each type of decedent- compute for the gross.pdfkingsandqueens3
 
Problem IV - Stock Investments Mal- Inc- acquired 25- of the outstandi.pdf
Problem IV - Stock Investments Mal- Inc- acquired 25- of the outstandi.pdfProblem IV - Stock Investments Mal- Inc- acquired 25- of the outstandi.pdf
Problem IV - Stock Investments Mal- Inc- acquired 25- of the outstandi.pdfkingsandqueens3
 
Problem E Let X be the number of heads in n flips of a coin with proba.pdf
Problem E Let X be the number of heads in n flips of a coin with proba.pdfProblem E Let X be the number of heads in n flips of a coin with proba.pdf
Problem E Let X be the number of heads in n flips of a coin with proba.pdfkingsandqueens3
 
Problem C- Huntington's disease results from the presence of a dominan.pdf
Problem C- Huntington's disease results from the presence of a dominan.pdfProblem C- Huntington's disease results from the presence of a dominan.pdf
Problem C- Huntington's disease results from the presence of a dominan.pdfkingsandqueens3
 
Problem B (5 points)- A medical sociologist investigated the relations.pdf
Problem B (5 points)- A medical sociologist investigated the relations.pdfProblem B (5 points)- A medical sociologist investigated the relations.pdf
Problem B (5 points)- A medical sociologist investigated the relations.pdfkingsandqueens3
 
Problem 9- (4 marks) Let symbol denote -exclusive or - that is pq(pq).pdf
Problem 9- (4 marks) Let symbol  denote -exclusive or - that is pq(pq).pdfProblem 9- (4 marks) Let symbol  denote -exclusive or - that is pq(pq).pdf
Problem 9- (4 marks) Let symbol denote -exclusive or - that is pq(pq).pdfkingsandqueens3
 
Problem 6 (4 marks) Matt and Sandeep are partners with capital balance.pdf
Problem 6 (4 marks) Matt and Sandeep are partners with capital balance.pdfProblem 6 (4 marks) Matt and Sandeep are partners with capital balance.pdf
Problem 6 (4 marks) Matt and Sandeep are partners with capital balance.pdfkingsandqueens3
 
Problem 6 The function -move- takes as input a list of numbers- Explai.pdf
Problem 6 The function -move- takes as input a list of numbers- Explai.pdfProblem 6 The function -move- takes as input a list of numbers- Explai.pdf
Problem 6 The function -move- takes as input a list of numbers- Explai.pdfkingsandqueens3
 
Problem 5- Assume 5 points are placed into an equilateral triangle of.pdf
Problem 5- Assume 5 points are placed into an equilateral triangle of.pdfProblem 5- Assume 5 points are placed into an equilateral triangle of.pdf
Problem 5- Assume 5 points are placed into an equilateral triangle of.pdfkingsandqueens3
 
Problem 4- Show that in the recurrence T(n)-0qn1max(T(q)+T(nq1))+n- T(.pdf
Problem 4- Show that in the recurrence T(n)-0qn1max(T(q)+T(nq1))+n- T(.pdfProblem 4- Show that in the recurrence T(n)-0qn1max(T(q)+T(nq1))+n- T(.pdf
Problem 4- Show that in the recurrence T(n)-0qn1max(T(q)+T(nq1))+n- T(.pdfkingsandqueens3
 
Problem 4 An analyst has a dataset of n-1-000 observations of (Yi-Xi)-.pdf
Problem 4 An analyst has a dataset of n-1-000 observations of (Yi-Xi)-.pdfProblem 4 An analyst has a dataset of n-1-000 observations of (Yi-Xi)-.pdf
Problem 4 An analyst has a dataset of n-1-000 observations of (Yi-Xi)-.pdfkingsandqueens3
 
Problem 4- Repeated Permutations a) In how many ways the letters of th.pdf
Problem 4- Repeated Permutations a) In how many ways the letters of th.pdfProblem 4- Repeated Permutations a) In how many ways the letters of th.pdf
Problem 4- Repeated Permutations a) In how many ways the letters of th.pdfkingsandqueens3
 
Problem 4 Suppose that the returns to education is 13-4- per year for.pdf
Problem 4 Suppose that the returns to education is 13-4- per year for.pdfProblem 4 Suppose that the returns to education is 13-4- per year for.pdf
Problem 4 Suppose that the returns to education is 13-4- per year for.pdfkingsandqueens3
 

More from kingsandqueens3 (20)

products apperar below Assume that sulficient time is available on the.pdf
products apperar below Assume that sulficient time is available on the.pdfproducts apperar below Assume that sulficient time is available on the.pdf
products apperar below Assume that sulficient time is available on the.pdf
 
Procedure for Activity 1-2- Applying Directional Terms Part 1 Procedur.pdf
Procedure for Activity 1-2- Applying Directional Terms Part 1 Procedur.pdfProcedure for Activity 1-2- Applying Directional Terms Part 1 Procedur.pdf
Procedure for Activity 1-2- Applying Directional Terms Part 1 Procedur.pdf
 
process- and conversion costs are added everly during the peocess- Spo.pdf
process- and conversion costs are added everly during the peocess- Spo.pdfprocess- and conversion costs are added everly during the peocess- Spo.pdf
process- and conversion costs are added everly during the peocess- Spo.pdf
 
Process capability A- exists when CPK is less than 1-0- B- means that.pdf
Process capability A- exists when CPK is less than 1-0- B- means that.pdfProcess capability A- exists when CPK is less than 1-0- B- means that.pdf
Process capability A- exists when CPK is less than 1-0- B- means that.pdf
 
Problem VII - Debt and Stock Investments Cam Inc- has decided to inves.pdf
Problem VII - Debt and Stock Investments Cam Inc- has decided to inves.pdfProblem VII - Debt and Stock Investments Cam Inc- has decided to inves.pdf
Problem VII - Debt and Stock Investments Cam Inc- has decided to inves.pdf
 
Problem V-Fair Value Adiustment HQ Inc- has the following trading port.pdf
Problem V-Fair Value Adiustment HQ Inc- has the following trading port.pdfProblem V-Fair Value Adiustment HQ Inc- has the following trading port.pdf
Problem V-Fair Value Adiustment HQ Inc- has the following trading port.pdf
 
Problem Statement Several students in our college struggle with academ.pdf
Problem Statement Several students in our college struggle with academ.pdfProblem Statement Several students in our college struggle with academ.pdf
Problem Statement Several students in our college struggle with academ.pdf
 
Problem Gross Estate For each type of decedent- compute for the gross.pdf
Problem Gross Estate For each type of decedent- compute for the gross.pdfProblem Gross Estate For each type of decedent- compute for the gross.pdf
Problem Gross Estate For each type of decedent- compute for the gross.pdf
 
Problem IV - Stock Investments Mal- Inc- acquired 25- of the outstandi.pdf
Problem IV - Stock Investments Mal- Inc- acquired 25- of the outstandi.pdfProblem IV - Stock Investments Mal- Inc- acquired 25- of the outstandi.pdf
Problem IV - Stock Investments Mal- Inc- acquired 25- of the outstandi.pdf
 
Problem E Let X be the number of heads in n flips of a coin with proba.pdf
Problem E Let X be the number of heads in n flips of a coin with proba.pdfProblem E Let X be the number of heads in n flips of a coin with proba.pdf
Problem E Let X be the number of heads in n flips of a coin with proba.pdf
 
Problem C- Huntington's disease results from the presence of a dominan.pdf
Problem C- Huntington's disease results from the presence of a dominan.pdfProblem C- Huntington's disease results from the presence of a dominan.pdf
Problem C- Huntington's disease results from the presence of a dominan.pdf
 
Problem B (5 points)- A medical sociologist investigated the relations.pdf
Problem B (5 points)- A medical sociologist investigated the relations.pdfProblem B (5 points)- A medical sociologist investigated the relations.pdf
Problem B (5 points)- A medical sociologist investigated the relations.pdf
 
Problem 9- (4 marks) Let symbol denote -exclusive or - that is pq(pq).pdf
Problem 9- (4 marks) Let symbol  denote -exclusive or - that is pq(pq).pdfProblem 9- (4 marks) Let symbol  denote -exclusive or - that is pq(pq).pdf
Problem 9- (4 marks) Let symbol denote -exclusive or - that is pq(pq).pdf
 
Problem 6 (4 marks) Matt and Sandeep are partners with capital balance.pdf
Problem 6 (4 marks) Matt and Sandeep are partners with capital balance.pdfProblem 6 (4 marks) Matt and Sandeep are partners with capital balance.pdf
Problem 6 (4 marks) Matt and Sandeep are partners with capital balance.pdf
 
Problem 6 The function -move- takes as input a list of numbers- Explai.pdf
Problem 6 The function -move- takes as input a list of numbers- Explai.pdfProblem 6 The function -move- takes as input a list of numbers- Explai.pdf
Problem 6 The function -move- takes as input a list of numbers- Explai.pdf
 
Problem 5- Assume 5 points are placed into an equilateral triangle of.pdf
Problem 5- Assume 5 points are placed into an equilateral triangle of.pdfProblem 5- Assume 5 points are placed into an equilateral triangle of.pdf
Problem 5- Assume 5 points are placed into an equilateral triangle of.pdf
 
Problem 4- Show that in the recurrence T(n)-0qn1max(T(q)+T(nq1))+n- T(.pdf
Problem 4- Show that in the recurrence T(n)-0qn1max(T(q)+T(nq1))+n- T(.pdfProblem 4- Show that in the recurrence T(n)-0qn1max(T(q)+T(nq1))+n- T(.pdf
Problem 4- Show that in the recurrence T(n)-0qn1max(T(q)+T(nq1))+n- T(.pdf
 
Problem 4 An analyst has a dataset of n-1-000 observations of (Yi-Xi)-.pdf
Problem 4 An analyst has a dataset of n-1-000 observations of (Yi-Xi)-.pdfProblem 4 An analyst has a dataset of n-1-000 observations of (Yi-Xi)-.pdf
Problem 4 An analyst has a dataset of n-1-000 observations of (Yi-Xi)-.pdf
 
Problem 4- Repeated Permutations a) In how many ways the letters of th.pdf
Problem 4- Repeated Permutations a) In how many ways the letters of th.pdfProblem 4- Repeated Permutations a) In how many ways the letters of th.pdf
Problem 4- Repeated Permutations a) In how many ways the letters of th.pdf
 
Problem 4 Suppose that the returns to education is 13-4- per year for.pdf
Problem 4 Suppose that the returns to education is 13-4- per year for.pdfProblem 4 Suppose that the returns to education is 13-4- per year for.pdf
Problem 4 Suppose that the returns to education is 13-4- per year for.pdf
 

Recently uploaded

Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 

Recently uploaded (20)

Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 

Problem- Describe an algorithm for concatenating two singly linked lis.pdf

  • 1. Problem: Describe an algorithm for concatenating two singly linked lists L and M, into a single list L that contains all the nodes of L followed by all the nodes of M. Modify the SinglyLinkedList class to contain the method: public void concatenate(SinglyLinkedList other) { ... } PLEASE PLEASE USE THE CODE BELOW..... THANK YOU public class SinglyLinkedList<E> implements Cloneable { //---------------- nested Node class ---------------- /** * Node of a singly linked list, which stores a reference to its * element and to the subsequent node in the list (or null if this * is the last node). */ private static class Node<E> { /** The element stored at this node */ private E element; // reference to the element stored at this node /** A reference to the subsequent node in the list */ private Node<E> next; // reference to the subsequent node in the list /** * Creates a node with the given element and next node. * * @param e the element to be stored * @param n reference to a node that should follow the new node */ public Node(E e, Node<E> n) { element = e; next = n; } // Accessor methods /** * Returns the element stored at the node. * @return the element stored at the node */ public E getElement() { return element; } /** * Returns the node that follows this one (or null if no such node). * @return the following node */ public Node<E> getNext() { return next; }
  • 2. // Modifier methods /** * Sets the node's next reference to point to Node n. * @param n the node that should follow this one */ public void setNext(Node<E> n) { next = n; } } //----------- end of nested Node class ----------- // instance variables of the SinglyLinkedList /** The head node of the list */ private Node<E> head = null; // head node of the list (or null if empty) /** The last node of the list */ private Node<E> tail = null; // last node of the list (or null if empty) /** Number of nodes in the list */ private int size = 0; // number of nodes in the list /** Constructs an initially empty list. */ public SinglyLinkedList() { } // constructs an initially empty list // access methods /** * Returns the number of elements in the linked list. * @return number of elements in the linked list */ public int size() { return size; } /** * Tests whether the linked list is empty. * @return true if the linked list is empty, false otherwise */ public boolean isEmpty() { return size == 0; } /** * Returns (but does not remove) the first element of the list * @return element at the front of the list (or null if empty) */ public E first() { // returns (but does not remove) the first element if (isEmpty()) return null; return head.getElement(); } /** * Returns (but does not remove) the last element of the list. * @return element at the end of the list (or null if empty)
  • 3. */ public E last() { // returns (but does not remove) the last element if (isEmpty()) return null; return tail.getElement(); } // update methods /** * Adds an element to the front of the list. * @param e the new element to add */ public void addFirst(E e) { // adds element e to the front of the list head = new Node<>(e, head); // create and link a new node if (size == 0) tail = head; // special case: new node becomes tail also size++; } /** * Adds an element to the end of the list. * @param e the new element to add */ public void addLast(E e) { // adds element e to the end of the list Node<E> newest = new Node<>(e, null); // node will eventually be the tail if (isEmpty()) head = newest; // special case: previously empty list else tail.setNext(newest); // new node after existing tail tail = newest; // new node becomes the tail size++; } /** * Removes and returns the first element of the list. * @return the removed element (or null if empty) */ public E removeFirst() { // removes and returns the first element if (isEmpty()) return null; // nothing to remove E answer = head.getElement(); head = head.getNext(); // will become null if list had only one node size--; if (size == 0) tail = null; // special case as list is now empty return answer; }
  • 4. @SuppressWarnings({"unchecked"}) public boolean equals(Object o) { if (o == null) return false; if (getClass() != o.getClass()) return false; SinglyLinkedList other = (SinglyLinkedList) o; // use nonparameterized type if (size != other.size) return false; Node walkA = head; // traverse the primary list Node walkB = other.head; // traverse the secondary list while (walkA != null) { if (!walkA.getElement().equals(walkB.getElement())) return false; //mismatch walkA = walkA.getNext(); walkB = walkB.getNext(); } return true; // if we reach this, everything matched successfully } @SuppressWarnings({"unchecked"}) public SinglyLinkedList<E> clone() throws CloneNotSupportedException { // always use inherited Object.clone() to create the initial copy SinglyLinkedList<E> other = (SinglyLinkedList<E>) super.clone(); // safe cast if (size > 0) { // we need independent chain of nodes other.head = new Node<>(head.getElement(), null); Node<E> walk = head.getNext(); // walk through remainder of original list Node<E> otherTail = other.head; // remember most recently created node while (walk != null) { // make a new node storing same element Node<E> newest = new Node<>(walk.getElement(), null); otherTail.setNext(newest); // link previous node to this one otherTail = newest; walk = walk.getNext(); } } return other; } public int hashCode() { int h = 0; for (Node walk=head; walk != null; walk = walk.getNext()) { h ^= walk.getElement().hashCode(); // bitwise exclusive-or with element's code h = (h << 5) | (h >>> 27); // 5-bit cyclic shift of composite code } return h; } /** * Produces a string representation of the contents of the list. * This exists for debugging purposes only.
  • 5. */ public String toString() { StringBuilder sb = new StringBuilder("("); Node<E> walk = head; while (walk != null) { sb.append(walk.getElement()); if (walk != tail) sb.append(", "); walk = walk.getNext(); } sb.append(")"); return sb.toString(); } public void concatenate(SinglyLinkedList<E> other) { ............. TYPE CODE HERE......... } } }