c++ - How to check if double linked list is a pallindrome without using extra space? -


recently went interview , asked me "to check if below double linked list pallindrome without using storage stl's, linked-list, stack, queue, tree, string, character arrays. etc.." unable give perfect solution though.

below image view.

enter image description here

this not homework question merely question find solutions shared.

declare 2 iterators, start , end. loop through list , decrement/increment them simultaneously, comparing @ each step. note: algorithm assumes have overridden operators, works sort of list, not numerical lists.

for(int i=0;i<list.size()/2;i++){     if(*start!=*end) return false;     start++;     end--; } return true; 

the key here using iterators instead of working list directly.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -