c++ - How to check Palindromic lists -
i know how can write function determine if list read in bellow code palindromic? e.g if list of numbers 123456 program print out "this list not palindrome" , if list 12321 print out "this list palindrome".
any appreciated.
void poparray(int array1[]) { ifstream infile("test1.txt"); if (!infile) { cout << "can't open file: " << endl; exit(exit_failure); } (int = 0; < 10; i++) { infile >> array1[i]; cout << setw(2) << array1[i]; } } void reverselist(int array1[]) { (int x = 9; x > -1; x--) { cout << setw(2) << array1[x]; } }
i'd suggest using index i
, have go 0
size/2
. inside loop comparing list[i] == list[(size - 1) - ]
.
Comments
Post a Comment