Question: Implement the ordered version of removeElement in the window below. Your function should validate inputs and remove the element in the given position by moving

Implement the ordered version of removeElement in the window below. Your function should validate inputs and remove the element in the given position by moving all of the other elements down.

//why isn't this code working and what can i fix?

#include using namespace std; // removeElement preserves the order of the remaining elements in the array. // @param: char array that is ordered in some way. // @param: int numElems is the number of elements // @param: int position of the element being removed // @returns true if the element is removed, false otherwise. // be careful to use reference parameters where necessary!

bool removeElement(char array[], int numElems, int position){ if(position <=0 || position > numElems){ cout << "Invalid position "; return false; } else{ for (int i=position-1; i

int main() { char array[5]={'a','b','c','d','e'}; bool result=removeElement(array,5,3); if (result == true){ cout << "Element is removed "; } else{ cout << "Element is not found"; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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

Students Have Also Explored These Related Databases Questions!