Traverse linked list until last node is equal to loop_start and store the elements till start in a stack
count = 0 NEW_LINE while ( ptr != loop_start or count != 1 ) : NEW_LINE INDENT s . append ( ptr . data ) NEW_LINE if ( ptr == loop_start ) : NEW_LINE INDENT count = 1 NEW_LINE DEDENT ptr = ptr . next NEW_LINE DEDENT ptr = head NEW_LINE count = 0 NEW_LINE