Question

In: Computer Science

Given two sorted lists L1 and L2, write a procedure to compute L1∪L2 using only the...

Given two sorted lists L1 and L2, write a procedure to compute L1∪L2 using only the basic list operations. Pseudo-code is acceptable.

Solutions

Expert Solution

SOURCE CODE

   ListIterator l1 = L1.iterator();
   ListIterator l2 = L2.iterator();
   int i = 0;
   if(l1.hasNext() && l2.hasNext())
   {
       item1 = l1.next();
       item2 = l2.next();
   }
   while(item1 != null && item2 != null)
   {
       res = item1.compareTo(item2);
       if(res == 0)
       {
           L3.add(item1)
           item1 = (l1.hasNext())? l1.next() : null;
           item2 = (l2.hasNext())? l2.next() : null;
       }
       else if(res > 0)
       {
           L3.add(item2);
           item2 = (l2.hasNext())? l2.next() : null;
       }
       else
       {
           L3.add(item1);
           item1 = (l1.hasNext())? l1.next() : null;
       }
   }

SCREENSHOT

please give a upvote if u feel helpful.


Related Solutions

Given two sorted lists, L1 and L2, write an efficient C++ code to compute L1 ∩...
Given two sorted lists, L1 and L2, write an efficient C++ code to compute L1 ∩ L2 using only the basic STL list operations. What is the running time of your algorithm?
The intersection of two lists L1 and L2, L1 ∩ L2, is defined as the list...
The intersection of two lists L1 and L2, L1 ∩ L2, is defined as the list containing elements in both L1 and L2 only. Given two sorted lists L1 and L2, write a function, called intersection, to compute L1 ∩ L2 using only the basic list operations. The intersection function is defined as follows template list intersection( const list & L1, const list & L2); C++
Problem 1: You have two sorted lists of integers, L1 and L2. You know the lengths...
Problem 1: You have two sorted lists of integers, L1 and L2. You know the lengths of each list, L1 has length N1 and L2 has length N2. Design a linear running time complexity algorithm (ONLY PSEUDOCODE) to output a sorted list L1 ∧ L2 (the intersection of L1 and L2). Important Notes: For this problem, you don’t need to submit any implementation in Java. Only the pseudocode of your algorithm is required. Pseudocode is a simple way of writing...
1) Equations for two lines L1 and L2 are given. Find the angle between L1 and...
1) Equations for two lines L1 and L2 are given. Find the angle between L1 and L2. L1: ? = 7 + 2?, ? = 8 − 4?, ? = −9 + ? L2: ? = −8 − ?, ? = 3 − 3?, ? = 4 + 3? 2) Find polar form of complex number z : ?) ? = 4√3 − 4? ?) ? = 2√3 − 2i
Given lists L1, L2 and L3, delete all the nodes having even number in info part...
Given lists L1, L2 and L3, delete all the nodes having even number in info part from the list L1 and insert into list L2 and all the nodes having odd numbers into list L3. Code needed in java.
1. Write a Racket function (set-equal? L1 L2) that tests whether L1 and L2 are equal....
1. Write a Racket function (set-equal? L1 L2) that tests whether L1 and L2 are equal. Two sets are equal if they contain exactly the same members, ignoring ordering (or in other words, two sets are equal if they are a subset of each other). For example (set-equal? '(1 (2 3)) '((3 2) 1)) ---> #t (set-equal? '(1 2 3) '((3 2)1)) ---> #f (set-equal? '(1 2 3) '((1 2 3))) ---> #f 2. Two common operations on sets are...
Given two sorted linked lists, merge them into a third sorted linked list. If an element...
Given two sorted linked lists, merge them into a third sorted linked list. If an element is present in both the lists, it should occur only once in the third list. Code needed in java.
how do i construct a scatterplot if L1 lists negative values and L2 has values such...
how do i construct a scatterplot if L1 lists negative values and L2 has values such as 0.00339156, 0.00326318, 0.00313725 ? Do i enter the L2 values as exponents??
Write a program to compute intersection of two sorted array of integers and compute the CPU...
Write a program to compute intersection of two sorted array of integers and compute the CPU time for different sets of unsigned integers generated by a random number generator. Test this using the same data sets: atleast 3 of size 1000 integers, atleast 3 of size 10000 integers, atleast 3 of size 100000 integers, atleast 3 of one million integers and atleast 3 of size 10 million integers DONT FORGET CPU TIME FOR EACH ONE NO HASH SET
Recall that given a line L1 in the plane with slope m, a second line L2...
Recall that given a line L1 in the plane with slope m, a second line L2 is perpendicular to L1 if and only if the slope of L2 is − 1 m . Now consider the function h(x) = x^2 + 3/2x + 3. Among all of the lines tangent to the graph of h(x), there is exactly one which is perpendicular to the line given by y = −2x + 7. Write the equation of that line tangent to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT