Question: Write an algorithm for a function called removeAll which takes 3 parameters: an array of array type, a count of elements in the array, and

Write an algorithm for a function called removeAll which takes 3 parameters: an array of array type, a count of elements in the array, and a value. As with the remove method we discussed in class, elements passed the count of elements are stored as None. This function should remove all occurrences of value and then shift the remaining data down. The last populated element in the array should then be set to None. The function then returns the count of “valid” (i.e. non-removed) data elements left. This function should do the removal “by hand” and SHOULD NOT use the remove method.

 

Hint: Consider what how you update your current position in an array when you don’t remove an element versus when you do remove an element.

Python

Step by Step Solution

3.42 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

def removealll n val while1 flag ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

635f8c9188109_232746.pdf

180 KBs PDF File

Word file Icon

635f8c9188109_232746.docx

120 KBs Word File

Students Have Also Explored These Related Algorithms Questions!