Like I said in my subject line, I'm sorry to ask what would look like such a stupid question since I wrote the program myself, but this recursive stuff has me somewhat baffled at how complex it could possibly be, and the book examples are trash since I am not good in math.
Book def of ...
Recursive definition - A definition in which something is defined in terms of a smaller version of itslef.
Recursive algorithm - An algorithm given to a problem by reducing the problem to smaller versions of itself.
Recursive function - A FUNCTION THAT CALLS ITSLEF.
The def of a recursive function is what I am not understanding, why is this not a function to reduce a problem to a smaller version of itself then calling it (saving all the parameters) again.
Regardless is the function I've written in the following program considered a recursive function??? Again I'm sorry to ask, but this is the second time I've written this program, because my first one wasn't considered "recursive"
2006-11-05
17:35:24
·
4 answers
·
asked by
D
4
in
Computers & Internet
➔ Programming & Design
#include
#include
using namespace std;
bool palindrome(char word[],int listsize, int first);
int main()
{
//Declare local variables
char breakapart[100] = {0};
int listsize = 0;
int first = 0;
char *word;
//Get input from user
cout << "Hello user " << endl;
cout << "Please enter a word for me to check to see if the word is a palindrome or not " << endl;
cin >> breakapart;
//"Find out" the size the word entered
for (int i = 0;i < 100;i++)
{
cout << i << endl;
if (breakapart[i] != 0)
listsize++;
}
//Error check...delete before final product
//Used to find listsize value...had runtime error
//on NOV 4
cout << "Value of listsize " << listsize - 1 << endl;
//End ERROR CHECK***
//Assign memory array addresses to pointers
word = new char[listsize];
//Copy only "valid" data into first array
for (int i = 0; i < listsize; i++)
word[i] = breakapart[i];
//Call function palindrome
palindrome(word,listsize,first);
//Pause sytem after program execution
2006-11-05
17:35:39 ·
update #1
return 0;
}
bool palindrome(char word[],int listsize, int first)
{
//Error check...delete before final product
cout << "value of first" << first << " " << word[first] << endl;
cout << "Value of last " << listsize << " " << word[listsize - 1] << endl;
//End error check***
//If statement will return true ONLY if word entered is a palindrome
//Else if statment will return ONLY if the word entered is NOT a palindrome
//Else Statement will increment/decrement the counters and recall the function
//until a true or false condition is returned
if (first == listsize -1)
{
cout << "the word entered IS a palindrome " << endl;
return true;
}
else if (word[first] != word[listsize-1])
{
cout << "the word entered is not a palindrome " << endl;
return false;
}
else
{
first++;
listsize--;
palindrome(word,listsize,first);
}
}
2006-11-05
17:36:04 ·
update #2
Oh by the way, if you haven't figured out yet. This program requires a recursive function, and it is a program to check weather a word is a palindrome or not.
2006-11-05
17:39:41 ·
update #3