Question

5. (4 points) Define a function named insert that takes an integer atom and a sorted list as parameters. The function should return a list with the integer in the correct position in the sorted list. For example: insert 3, (24 68)] (2 3 4 6 8) insert 9, (9) insert[ 3, (2 3 4 5)] (23 3 4 5 Note that in the case of that last example, it does not matter which 3 comes first in the final list (the parameter or the one from the sorted list). Your solution must provide both the design notation used in class and an implementation of that design in Scheme. Test your code using the interpreter on stolinux to check your work. As above, use only the elements we have discussed in class to write this code.

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

def insert(atom, arr):
for idx, val in enumerate(arr):
if val > atom:
arr.insert(idx, atom)
return
arr.insert(len(arr),atom)
return


def main():
x = [1,3,5,999]
insert(9,x)
print x


main()

Add a comment
Know the answer?
Add Answer to:
Define a function named insert that takes an integer atom and a sorted list as parameters....
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