Answer 4 out of 5 questions below Explain what does the foll
Answer 4 out of 5 questions below Explain what does the following function do List *foo (List *l1, List *l2) { if(l1 rightarrow isEmpty()) return l2; else if (l2 rightarrow isEmpty()) retrun l1; else { l1- >tail rightarrow next = l2 rightarrow head; l2- >head rightarrow prev = l1 rightarrow tail; return l1; } }
Solution
The function concatenates the lists l1 and l2. The first if condition checks if l1 is empty, so the concatenation will effectively give l2. The second condition checks if l2 is empty, so the concatenation will effectively give l2. If both are not empty then we add l2 at the end of l1 and return l1. Now l1 is the concatenated version.
