Reverse a playlist in place
Flip the order of a playlist array without making a second array, by swapping from both ends towards the middle.
A playlist is an array of song titles: const char *songs[], each item a pointer to a string. Write reverse_playlist(songs, n) so that afterwards the array holds the same songs in the opposite order. Do it in place: no second array, no malloc. The songs themselves do not change, only which slot points at which title.
C
const char *songs[] = {"Intro", "Neon Rain", "Static", "Outro"};
reverse_playlist(songs, 4);
// songs is now {"Outro", "Static", "Neon Rain", "Intro"}Constraint
- Reverse in place, without malloc.
Checks
- An even number of songs
- Odd, single and empty
exercise_1.c to run
void reverse_playlist(const char **songs, int n) {
}