Question

c++ Write pseudocode that merges two sorted lists into a new third sorted list by using...

c++

Write pseudocode that merges two sorted lists into a new third sorted list by using only ADT sorted list operations.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: The pseudocode has been explained with neat comments

//function returns list

list mergeTwoSortedLists(listA, listB){

resList; //3rd list

l1 = lenght of listA

l2 = lenght of listB

while(i<l1 && j<l2){

if(listA[i] < listB[i]{

resList[k] = listA[i];

i++; K++;

}

else{

resList[k] = listB[i];

j++; K++;

}

}

// if listA contains more elements than listB

while(i<l1){

resList[k] = listA[i];

i++; K++;

}

// if listB contains more elements than listA

while(i<l2){

resList[k] = listB[i];

j++; K++;

}

return resList;

}

Add a comment
Know the answer?
Add Answer to:
c++ Write pseudocode that merges two sorted lists into a new third sorted list by using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT