Anonymous user
Dutch national flag problem: Difference between revisions
m
no edit summary
mNo edit summary |
mNo edit summary |
||
Line 27:
generate_unsorted_sequence
importing
returning
value(
sort_sequence
is_sorted
importing
returning
value(
endinterface.
Line 53 ⟶ 51:
constants:
begin of dutch_flag_colors,
red type char1 value
white type char1 value
blue type char1 value
end of dutch_flag_colors.
endclass.
Line 67 ⟶ 65:
max = 2 ).
▲ do i_length - 1 times.
data(random_int) = random_int_generator->get_next( ).
Line 77 ⟶ 73:
when random_int eq 2 then dutch_flag_colors-blue ).
enddo.
if strlen(
random_int = random_int_generator->get_next( ).
Line 87 ⟶ 83:
when random_int eq 1 then dutch_flag_colors-white ).
endif.
endmethod.
method sorting_problem~sort_sequence.
data(low_index) = 0.
data(middle_index) = 0.
data(high_index) = strlen(
while middle_index <= high_index.
data(current_color) =
if current_color eq dutch_flag_colors-red.
data(buffer) =
val =
off = middle_index
len = 1
with = buffer ).
val =
off = low_index
len = 1
Line 122 ⟶ 115:
middle_index = middle_index + 1.
elseif current_color eq dutch_flag_colors-blue.
buffer =
val =
off = middle_index
len = 1
with = buffer ).
val =
off = high_index
len = 1
Line 141 ⟶ 134:
endif.
endwhile.
endmethod.
method sorting_problem~is_sorted.
do strlen(
data(current_character_index) = sy-index - 1.
data(current_color) =
data(next_color) =
when ( current_color eq dutch_flag_colors-red and
( next_color eq current_color or
Line 166 ⟶ 157:
( current_color eq dutch_flag_colors-blue and
current_color eq next_color )
then
else abap_false ).
check
return.
enddo.
Line 181 ⟶ 172:
dutch_national_flag_problem = new dutch_national_flag_problem( ).
data(
write:|{
</lang>
|