Java
public MyLinkedList merge(MyLinkedList list2)
{
MyLinkedList list3 = list2;
Node ptr = head;
while (ptr != null) {
list3.insertEnd(ptr.getInfo());
ptr = ptr.getLink();
}
return list3;
}
output
list 1 :
42 30 29 35 23
list 2 :
57 38 55 40 23 33 22 59
merage list 1 and list 2
42 30 29 35 23 57 38 55 40 23 33
22 59
I want to print the number once in the merage list?
Please find the answer below::
MyLinkedList.java
package classes1;
public class MyLinkedList {
Node head;
class Node {
int data;
Node next;
Node(int d) {
data = d;
next =
null;
}
public int getInfo() {
return
data;
}
public Node getLink() {
return
next;
}
}
Node reverse(Node node) {
Node prev = null;
Node current = node;
Node next = null;
while (current != null) {
next =
current.next;
current.next =
prev;
prev =
current;
current =
next;
}
node = prev;
return node;
}
public MyLinkedList merge(MyLinkedList list2)
{
MyLinkedList list3 = list2;
Node ptr = head;
while (ptr != null) {
list3.insertEnd(ptr.getInfo());
ptr = ptr.getLink();
}
return list3;
}
void insertEnd(int value) {
Node listnode = new
Node(value);
listnode.next = null;
if(head == null) {
head=listnode;
}
else {
Node temp =
head;
while(temp.next!=null){
temp = temp.next;
}
temp.next =
listnode;
}
}
void printList() {
Node node = head;
while (node != null) {
System.out.print(node.data + " ");
node =
node.next;
}
}
public static void main(String[] args) {
MyLinkedList list1 = new
MyLinkedList ();
list1.insertEnd(42);
list1.insertEnd(30);
list1.insertEnd(29);
list1.insertEnd(35);
list1.insertEnd(23);
System.out.println("List
1");
list1.printList();
MyLinkedList list2 = new
MyLinkedList ();
list2.insertEnd(57);
list2.insertEnd(38);
list2.insertEnd(55);
list2.insertEnd(40);
list2.insertEnd(23);
list2.insertEnd(33);
list2.insertEnd(22);
list2.insertEnd(59);
System.out.println("\nList
2");
list2.printList();
MyLinkedList list3 =
list2.merge(list1);
System.out.println("\nList
3");
list3.printList();
}
}
output:

Java public MyLinkedList merge(MyLinkedList list2) { MyLinkedList list3 = list2; Node ptr = head; while (ptr...
c++
5. You're given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more than once. The given head pointer may be null indicating that the list is empty. Enter numbers ending with -999 for the linked list: 3 7 11 11 11 24 27 30 42 42 47 55 55 78 89-999...
Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...
JAVA LANG PLEASE: I have follwed these below guidelines but when i run my queue test it is not executing but my stack is working fine, can you fix it please! MyQueue.java Implement a queue using the MyStack.java implementation as your data structure. In other words, your instance variable to hold the queue items will be a MyStack class. enqueue(String item): inserts item into the queue dequeue(): returns and deletes the first element in the queue isEmpty(): returns true or false...
These are my instructions: Your data should have been read in from the data file and stored into an array. Next you need to calculate the following and display in a single Message box: Average score Highest score Lowest score Mode of the scores Your program should be written using methods and should be well documented internally and externally. Your output should be displayed using Message boxes. This is the .text file to use with the instructions: 20 21 22...
5) An N-point moving-average (running-average) system has the following input-output relation ship: N-1 a) Is the N-point moving-average system causal? b) Obtain the expression for the impulse response h[n] and sketch hin. c) Given the input sequence [n] below with 100 elements where the values of the index n change between 0 and 99: r-[21 22 22 21 18 19 21 20 19 23 23 22 23 25 27 30 31.5 32 33 32 28 29 28 29 30 32...
Calculate the range, mean, mode, median, Standard deviation Calculate the skewness and kurtosis for the above data and interpret the data. The following is data collected from the daily salary employees of ZZ COMPANY.. 68 19 43 11 37 30 19 67 65 34 96 23 93 73 46 39 21 12 89 52 33 21 18 57 80 56 91 62 56 48 84 23 78 96 49 36 90 42 65 15 43 36 65 59 34 71...
For Questions 1-2, use table below. It is data for two stocks over 30 days (it is sample data). Day High stock Sky stock Day High stock Sky stock 1 27 60 16 43 39 2 33 57 17 45 37 3 34 56 18 46 35 4 35 55 19 47 34 5 36 54 20 47 32 6 37 51 21 48 29 7 38 50 22 50 26 8 38 47 23 50 26 9 39 47...
Sample Data Sample Data Hour Sample Taken Hour Sample Taken 1 4 5 X 1 3 1 42 2 3 4 5 6 2 39 36 25 60 28 53 22 56 41 34 43 45 59 42 36 40 45 39 48 26 42 34 61 48 45 29 3 31 61 38 40 54 26 38 42 37 41 53 37 47 41 37 29 20 26 43 38 33 37 37 35 33 36 41 25 37...
1 The following data represents the number of innings pitched by the ERA leaders for the past few years 23, 30, 20, 27, 44, 26, 35, 20, 29. 29, 25, 15, 18, 27, 19, 22, 12, 26. 34. 15. 27, 35, 26, ald43 35, 14, 24, 12, 23. 31, 40. 35, 38, 57, 22. 42, 24, 21, 27, 33 1. Find the value that corresponds to the 70th percentile. 2. Identify all the outiiers 3. Construct a boxplot for the...
Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...