RANDOM STRING ARRAY GENERATION
by Timur Gudkov (modified: 2010 Oct 26)
- Tags:
- random
Hello everybody. I need to use generation of random string array in this program, please, help:
class INSERTION_SORT [X -> COMPARABLE]
feature -- Sorting
insertion_sort (a: ARRAY[X]) is require a_not_void: a /= Void local i, j: INTEGER value: X do from i := a.lower + 1 until i > a.upper loop value := a [i] from j := i - 1 until j < a.lower or a [j] <= value loop a [j + 1] := a [j] j := j - 1 end a [j + 1] := value i := i + 1 end ensure same_count: a.count = old a.count sorted: is_sorted (a, a.lower, a.upper) end
feature -- Status report
is_sorted (a: ARRAY[X]; min, max: INTEGER): BOOLEAN require a_not_void: a /= Void min_valid: a.valid_index (min) max_valid: a.valid_index (max) local i: INTEGER do Result := True from i := min invariant a.valid_index (i) until i >= max or not Result loop Result := a [i] <= a [i + 1] i := i + 1 end end
end
class INSERTION_SORT_TEST
create
make
feature -- Initialization
make is local i: INTEGER testarray_numeric: ARRAY [INTEGER_8] testarray_string: ARRAY [STRING] sorter_numeric: INSERTION_SORT [INTEGER_8] sorter_string: INSERTION_SORT [STRING] do create sorter_numeric create sorter_string testarray_numeric := <<3,8,0,6,7,4,2,1,9,3,1,8,3,9,2,0,9, 4,6,3,0,5,7,9,3,2,5,7,9,0,1,9,3,1>> sorter_numeric.insertion_sort (testarray_numeric) from i := testarray_numeric.lower until i >= testarray_numeric.upper loop io.put_integer (testarray_numeric [i]) io.put_string (",") i := i + 1 end io.put_integer (testarray_numeric [i]) io.put_new_line testarray_string := <<"Paris","London","Stockholm","Berlin","Oslo", "Rome","Madrid","Tallinn","Amsterdam","Dublin">> sorter_string.insertion_sort (testarray_string) from i := testarray_string.lower until i >= testarray_string.upper loop io.put_string (testarray_string [i]) io.put_string (",") i := i + 1 end io.put_string (testarray_string [i]) io.put_new_line end
end
And second question: how to set the size of array initially? For example in pascal: array [1..100] of string. Thanks.
This is not the place to ask questions, this is supposed to be a blog. Feel free to post such questions on our forums http://forums.eiffel.com or on our mailing list http://groups.eiffel.com.
I'm not sure to understand your first question, but for the second, you create an array using its creation procedure: a: ARRAY [STRING]
create a.make (1, 100)