Created
July 6, 2018 21:59
-
-
Save kalyco/7a3b16bfdfe381b725cdf74fb6a1e9b0 to your computer and use it in GitHub Desktop.
Check if the linked list is a palindrome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Linked List Question | |
// Check if the linked list is a palindrome | |
// set a node variable starting with mhead. | |
// Iterate through first half of LL | |
// append elements to a string | |
// if after first half, starting with last elem in array, | |
// compare to the first node. if != return false | |
// inc n each time. | |
// after loop, if still valid, return true | |
bool function palindrome() { | |
string a1[mSize/2]; | |
node n = mHead; | |
for(int i=0; i<mSize; i++) { | |
if (i<(mSize/2)) { | |
a.append(n.value); | |
} else { | |
if (a[(mSize/2 - i)] == n.data) return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment