Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- note
- description: "Summary description for {SELECTION_SORT}."
- author: ""
- date: "$Date$"
- revision: "$Revision$"
- class
- SELECTION_SORT
- feature
- index_of_min(ar: ARRAY [INTEGER]; lower: INTEGER):INTEGER
- --find index of smallest element in ar in the range of lower and the max index.
- require
- lower_positiv : lower >=1
- lower_in_range: lower <= ar.count
- ar_not_void: ar/= Void
- local
- i, min, index: INTEGER
- do
- from
- i:=lower
- min := ar.item (i)
- index := i
- until
- i+1 > ar.count
- loop
- if ar.item(i+1) < min then
- min := ar.item(i+1)
- index := i+1
- end
- i := i + 1
- end
- Result := index
- ensure
- result_is_set: Result /= Void
- end
- selectionsort (ar: ARRAY [INTEGER]):ARRAY[INTEGER]
- -- sort Array x with selectionsort
- require
- ar_not_void: ar/=VOID
- local
- i: INTEGER
- min_index: INTEGER
- ith: INTEGER
- do
- from
- i:=1
- until
- i= ar.count
- loop
- min_index := index_of_min(ar,i)
- ith:=ar[i]
- ar[i]:= ar[min_index]
- ar[min_index]:=ith
- i:= i+1
- end
- Result:= ar
- ensure
- Result_is_set: Result /= Void
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement