Skip to content

Instantly share code, notes, and snippets.

@mogutou1214
Created September 3, 2013 01:03
Show Gist options
  • Save mogutou1214/6418613 to your computer and use it in GitHub Desktop.
Save mogutou1214/6418613 to your computer and use it in GitHub Desktop.
Careercup 2.7 - Implement a function to check if a linked list is a palindrome. use a stack.
bool isPalindrome(node *head){
if(head==NULL) return false;
node *curr = head;
stack<int> s;
while(curr!=NULL){
s.push(curr->data);
curr = curr->next;
}
/*while(!s.empty()){
cout << s.top() << endl;
s.pop();
}
*/
curr = head;
while(curr!=NULL){
if(s.top()!=curr->data)
return false;
curr = curr->next;
s.pop();
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment