disks.hpp
// Algorithm that sorts disks using the lawnmower algorithm.

Algorithm that sorts disks using the lawnmower algorithm.
Algorithm that sorts disks using the lawnmower algorithm .
sorted_disks sort_lawnmower(const disk_state& before) 
{
    int count = 0;
    disk_state newState = before;
    if (newState.is_alternating()) 
    { 
        while (!newState.is_sorted())  
        {
            for (int index = 0; index < newState.total_count() - 1; index = index + 2) 
            { 
                if (newState.is_index(index + 1)) 
                {
                    if ((newState.get(index) == DISK_DARK) && (newState.get(index + 1) == DISK_LIGHT)) 
                    {
                        newState.swap(index);
                        count++;
                    }
                }
            }
            for (int j = newState.total_count() - 1; j > 0; j = j - 2) 
            { 
                if (newState.is_index(j + 1))
                {
                    if ((newState.get(j) == DISK_DARK) && (newState.get(j + 1) == DISK_LIGHT)) 
                    {
                        newState.swap(j);
                        count++;
                    }
                }
            }
        }
    }
    return sorted_disks(newState, count);
}
sorted_disks sort_lawnmower ( const disk_state & before ) { int count = 0 ; disk_state newState = before ; if ( newState . is_alternating ( ) ) { while ( ! newState . is_sorted ( ) ) { for ( int index = 0 ; index < newState . total_count ( ) - 1 ; index = index + 2 ) { if ( newState . is_index ( index + 1 ) ) { if ( ( newState . get ( index ) == DISK_DARK ) && ( newState . get ( index + 1 ) == DISK_LIGHT ) ) { newState . swap ( index ) ; count ++ ; } } } for ( int j = newState . total_count ( ) - 1 ; j > 0 ; j = j - 2 ) { if ( newState . is_index ( j + 1 ) ) { if ( ( newState . get ( j ) == DISK_DARK ) && ( newState . get ( j + 1 ) == DISK_LIGHT ) ) { newState . swap ( j ) ; count ++ ; } } } } } return sorted_disks ( newState , count ) ; }
Algorithm that sorts disks using the lawnmower algorithm.
Algorithm that sorts disks using the lawnmower algorithm .
// counter variable
 //checking if new state is alternating
 //while loop until not sorted
 //traversing disk state and incrementing count
 //traversing disk state and incrementing count
 //ending of while loop
