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++
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
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...
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...
(a) Find the cosine of the angle between the lines L1 and L2 whose vector equations are given below:
(a) Find the cosine of the angle between the lines L1 and L2 whose vector equations are given below: L1 : ~r1(t) = [1, 1, 1] + t[1, 2, 3] L2 : ~r2(t) = [1, 1, 1] + t[−1, 4, 2]. (b) Find the equation of the plane that contains both L1 and L2.
For the Poincare plane, find two lines L1 and L2 and a point P off each...
For the Poincare plane, find two lines L1 and L2 and a point P off each such that through P there are exactly two lines parallel to both L1 and L2.
ABC ltd is a circuit board producer and produces two products, L1 & L2. The company...
ABC ltd is a circuit board producer and produces two products, L1 & L2. The company currently uses traditional costing system for making business decisions. However, recently the company is considering a move towards the Activity-Based Costing (ABC) system. As one of the company’s accountant’s you have been asked to prepare a statement comparing both the costing methods for the next company board meeting. Your supervisor has given you the following quarterly data: - Total Indirect Costs for the quarter:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT