RSS Forums RSS
Please support our C++ advertiser: Programming Forums

stack palindrome problem?

Join Date: Jul 2005
Location: London
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: stack palindrome problem?

  #2  
Sep 13th, 2005
why stacks?
Heres a palindrome proggy i did for another board.
#include <iostream>
#include <string>
#include <cctype>

int IsMirrorPalindrome( const char* word, size_t length )
{
   if( length <= 1) return 1;
   else
   return ( (word[0] == word[length-1]) && IsMirrorPalindrome(word+1,length-2));
}

int IsPalindrome(std::string test)
{
   std::string tempcopy;
   std::string::iterator iter = test.begin();
   const std::string::iterator end = test.end();
   while ( iter != end )
   {
      const char c = *iter;
      if ( (!std::ispunct(c)) && (!std::isspace(c)) ) tempcopy.push_back(std::tolower(c));
      ++iter;
   }

   if (IsMirrorPalindrome(tempcopy.c_str(),tempcopy.length()))
      return 1;
   else
      return 0;
}


int main()
{
   std::string test;
   std::cout<<" enter string.... ";
   std::getline(std::cin,test);
   if (IsPalindrome(test))
      std::cout<<std::endl<<"palindrome"<<std::endl;
   else
      std::cout<<std::endl<<" not palindrome"<<std::endl;
   getchar();
}
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:46 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC