int moveToEnd(string a[], int n, int pos); Eliminate the item at position pos by copying all elements after it one place to the left. Put the item that was thus eliminated into the last position of the array. Return the original position of the item that was moved to the end. Here's an example: string people[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" }; int j = moveToEnd(people, 5, 1); // returns 1 // people now contains: "samwell" "margaery" "daenerys" "tyrion" "jon" Notwithstanding each function's behavior described above, all functions that return an int must return −1 if they are passed any bad arguments (e.g. a negative array size, or a position that would require looking at the contents of an element past the last element we're interested in). Unless otherwise noted, passing 0 to the function as the array size is not itself an error; it merely indicates the f
Write a function / program that does the following:
int moveToEnd(string a[], int n, int pos); Eliminate the item at position pos by copying all elements after it one place to the left. Put the item that was thus eliminated into the last position of the array. Return the original position of the item that was moved to the end. Here's an example:
string people[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" }; int j = moveToEnd(people, 5, 1); // returns 1 // people now contains: "samwell" "margaery" "daenerys" "tyrion" "jon"
Notwithstanding each function's behavior described above, all functions that return an int must return −1 if they are passed any bad arguments (e.g. a negative array size, or a position that would require looking at the contents of an element past the last element we're interested in). Unless otherwise noted, passing 0 to the function as the array size is not itself an error; it merely indicates the function should examine no elements of the array.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images