hi;

this for circular link list type , its to check whether a word is palindrom or not .
it dosen't work !
can you check it

this the insert function :

void InsertLast(const elemtype &Item)
{
Node <elemtype>*temp;

temp=new Node<elemtype>;
if ( temp==NULL)
{
cout<<"Full memory"<<endl;
return;
}

temp -> info=Item;
temp ->next=NULL;

if (isEmpty())
{
first=temp;
last=temp;
}

else
{
last->next=temp;
last=temp;
}

count++;
}

and this is the function Palindrom and the main :

bool IsPalindram( )
{
Node <elemtype>*cur1, *cur2;
bool found = true;
cur1= first;
cur2= last;
for (int i =0; i<(count/2)	; i++)
{
if ( cur1->info == cur2->info)
{
cur1= cur1->next;
cur2=cur2->back;
found = true;
}
else
{
return ( found = false );
break;
}
return found ;
}
}
};

void main ()
{
CircularLinkedListType<*char> List;

*char x;
cout<<" Enter the list  "<<endl;
cin>>x;

List.InsertLast(x);

List.print();
cout<<endl<<endl;
List.IsPalindram();
return;
}

That's not a circular list, by the way, it is just a regular, forward-only linked list.

What you've got there won't compile. When the compiler starts spitting out errors, look at the first error and the line number it says. Go to that line and fix that error then try to compile again.

The InsertLast() function belongs to a template class, so it should say

template <typename elemtype>
void CircularLinkedListType<elemtype>::InsertLast( const elemtype &Item ) {

at the top of the function. Please go re-read your textbook on how to use template classes and functions. The actual code inside the function is fine.

The IsPalindrome() function has the same problem. Also, because you are not indenting your code, you cannot see which two { and } match. There is a problem with them in this function.

In main(), you should have char x[ 100 ]; A char * is just a pointer, but it doesn't point to any chars anywhere. An array of 100 chars is different --there are actual chars you can use.

Also, you call List.IsPalindrome(), but totally ignore the boolean result. As a consequence, you can't tell the user whether or not the list is or isn't a palindrome. Try something like:

if (List.IsPalindrome()) cout << "Yeah! It is a palindrome!" << endl;
else cout << "Oh no! It is NOT a palindrome!" << endl;

Try to find some examples of functions that return boolean values, template functions, template classes, char arrays, and other things that you are using and do the same sort of thing for each.

Hope this helps.

That's not a circular list, by the way, it is just a regular, forward-only linked list.

What you've got there won't compile. When the compiler starts spitting out errors, look at the first error and the line number it says. Go to that line and fix that error then try to compile again.

The InsertLast() function belongs to a template class, so it should say

template <typename elemtype>
void CircularLinkedListType<elemtype>::InsertLast( const elemtype &Item ) {

at the top of the function. Please go re-read your textbook on how to use template classes and functions. The actual code inside the function is fine.

The IsPalindrome() function has the same problem. Also, because you are not indenting your code, you cannot see which two { and } match. There is a problem with them in this function.

In main(), you should have char x[ 100 ]; A char * is just a pointer, but it doesn't point to any chars anywhere. An array of 100 chars is different --there are actual chars you can use.

Also, you call List.IsPalindrome(), but totally ignore the boolean result. As a consequence, you can't tell the user whether or not the list is or isn't a palindrome. Try something like:

if (List.IsPalindrome()) cout << "Yeah! It is a palindrome!" << endl;
else cout << "Oh no! It is NOT a palindrome!" << endl;

Try to find some examples of functions that return boolean values, template functions, template classes, char arrays, and other things that you are using and do the same sort of thing for each.

Hope this helps.

i forget to say that functions were typing inside the class , so the prototype you wrote is not the case here .

will try and change char* to form you explain , and see
this was the point that i doubt

This article has been dead for over six months. Start a new discussion instead.