Question

Data Structure C++ Write pseudocode that merges two sorted lists into a new third sorted list...

Data Structure 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

The pseudocode to merge two sorted list is given below:

function mergeTwoSortedArray(Integer firstArray[], Integer secondArray[], mergeArray[])
declare integer variable i, j, k, n1, and n2

Set i to 0
Set j to 0
Set k to 0

Set n1 to the size of the first array

Set n2 to the size of the second array

while i<n1 AND j <n2
if firstArray[i] < secondArray[j]
mergeArray[k] = firstArray[i]

k = k+1

i = i+1
else
mergeArray[k] = secondArray[j]

k = k+1

j = j+1

End While

while i < n1
mergeArray[k] = firstArray[i]

k = k+1

   i = i+1

End While

while j < n2
mergeArray[k] = secondArray[j]

k = k+1

j = j+1

End While

End Function

Add a comment
Know the answer?
Add Answer to:
Data Structure C++ Write pseudocode that merges two sorted lists into a new third sorted list...
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