首页 > > 详细

调试C 、Java程序辅导、调试C、C编程调试

#include
#include
#include
using namespace std;
template//template declaration
//program for palindrome
bool palindrome(list l)
{
typename list::iterator it;//iterator to traverse list
typename list::iterator it1=--l.end();//iterator to traverse list from end
//here the list will compared from both ends if values are not equal then it will automatically terminates by returning false
for(it=l.begin();!(it==l.end());it++,it1--)
{
if(!(*it==*it1))//if both the values are not equal
{
return false;
}
}
//if loop completed successfully that means both forward and reverse are same then it will return true
return true;
}
template
void printlist(list l)//for printing list
{
typename list::iterator it;//iterator to traverse list
for(it=l.begin();!(it==l.end());it++)
{
coutint_list;
list char_list;
list bool_list;
int x = 0;
for (int i = 75; i >= 65; --i)
{
int_list.push_back(i);
char_list.push_back(static_cast(i + x));
if (i <= 70)
x += 2;
}
bool_list.push_back(true);
bool_list.push_back(false);
bool_list.push_back(false);
bool_list.push_back(true);
//print lists by calling printlist() and checking palindrome or not by calling palindrome()
printlist(int_list);
cout << (palindrome(int_list) ? " is " : " is not ") << "a palindrome\n";
printlist(char_list);
cout << (palindrome(char_list) ? " is " : " is not ") << "a palindrome\n";
printlist(bool_list);
cout << (palindrome(bool_list) ? " is " : " is not ") << "a palindrome\n";
system("PAUSE");
return 0;
}
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!