Hello, I'm very new at C++ and I have to write a code that uses a recursive function to reverse some characters within a boundary, so lets say I have A[1] == ‘A’ A[2] == ‘B’ A[3] == ‘C’ A[4] == ‘D’ A[5] == ‘E’ and I put in a boundary like reverse between 2 to 5 I will get
A[1] == ‘A’ A[2] == ‘E’ A[3] == ‘D’ A[4] == ‘C’ A[5] == ‘B’
So far this is what I have but I keep getting this link error and undefined symbol reallyReverse(char*, int, int)
include <iostream>
#include <string>
using namespace std;
void reversebound(int, int, int);
void reverse(char s[], int length);
void reallyReverse(char a[], int lo, int hi);
int main()
{
char line[80];
int start, end;
char c;
int length = 0;
//
// Get a string from the user
//
cout << "Enter a string up to 80 characters: ";
cin.get(c);
while (c != '\n' && length < 80)
{
line[length] = c;
length++;
cin.get(c);
}
//
// If line long enough, test reallyReverse directly
//
if (length > 1)
{
cout << "Reversing elements 1.." << length/2 << endl;
reallyReverse(line, 1, length/2);
for (int i=0; i<length; i++)
cout << line[i];
cout << endl;
// Restore original line
reallyReverse(line, 1, length/2);
}
//
// Reverse it
//
cout << "Reversing whole line" << endl;
reverse(line, length);
//
// Print it
//
for (int i=0; i<length; i++)
cout << line[i];
cout << endl;
}
void reverse(char s[], int length)
{
reallyReverse(s, 0, length-1);
}
void reallyReverse(char a[],int lo, int hi)
{
if (lo>=hi)
return;
char temp;
char *s2 = *a;
temp = s2[lo];
s2[lo] =s2[hi];
s2[hi]=temp;
reallyReverse(a,lo + 1, hi -1);
}