-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
46 lines (35 loc) · 1.04 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <fstream>
#include "LList.h"
using namespace std;
int main(int argc, char *argv[]) {
bool isDigit = false;
if (argc != 2) {
cout << "Usage" << argv[0] << "name of Input File" << endl;
}
auto linkedList_int = new LList<int>;
auto linkedList_char = new LList<char>;
ifstream listStream;
listStream.open(argv[1],ios::in);
char data_char;
while (listStream >> data_char) {
if(isdigit(data_char)) {
isDigit = true;
linkedList_int->append(data_char - '0');
}
else {
linkedList_char->append(data_char);
}
}
if(isDigit){
string palindrome = linkedList_int->isPalindrome() ? "\nIs" : "\nIs not";
linkedList_int->print();
cout<<palindrome<<" a palindrome."<<endl;
}else {
string palindrome = linkedList_char->isPalindrome() ? "\nIs" : "\nIs not";
linkedList_char->print();
cout<<palindrome<<" a palindrome."<<endl;
}
listStream.close();
return 0;
}