0

Hello

My task is to writ a function that takes in a char array & the array size as its parameters & reverses the array contents. I cannot use another array to reverse the contents.

I am using insert & erase function to reverse the array, although I dont know which library I am meant to use & the correct syntax of the commands(insert & erase)?

Libraries:

dequeue
list
map
string
set
multimap

Any Advice?

#include <iostream>

using namespace std;

void reverse (char a[], int n);

int main() {

	char x[5] = {'a', 'b', 'c', 'd', 'e'};

	reverse(x,5);

	return 0;
}

void reverse (char a[], int n) {

	for (int i=0; i<n; i++) {
		insert(a[i],a[n-i]);  // is this the correct sytax??
		erase(a[n-i]);        // or should it be a[i].insert();
	}
3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by firstPerson
0

Um, I not quite sure what you mean, but what I am trying to do is reverse the contents in an array

eg
from this: a,b,c,d,e

to this: e,d,c,b,a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.