Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program AlphaSorter;
- type
- wordsContainer = record
- Values : array[1..100] of string;
- Length : integer;
- end;
- var wordsList : wordsContainer;
- procedure FillWordArray(var arr : wordsContainer);
- var i:integer;
- begin
- write('How many words do you want to enter? N = ');
- readln(arr.Length);
- for i:=1 to arr.Length do
- begin
- write('Word(',i,'): ');
- readln(arr.Values[i]);
- end;
- end;
- procedure SwapElemetsAt(var arr : wordsContainer; i, j :integer);
- var aux:string;
- begin
- aux := arr.Values[i];
- arr.Values[i]:=arr.Values[j];
- arr.Values[j]:=aux;
- end;
- procedure QuickSort(var arr : wordsContainer; low : integer; high : integer);
- var i, j:integer; pivot:string;
- begin
- i := low;
- j := high;
- pivot := arr.Values[low + ((high-low) div 2)];
- while i <= j do
- begin
- while arr.Values[i] < pivot do
- i := i + 1;
- while arr.Values[j] > pivot do
- j := j - 1;
- if i <= j then
- begin
- SwapElemetsAt(arr, i, j);
- i := i + 1;
- j := j - 1;
- end;
- // Recursion
- if low < j then
- QuickSort(arr, low, j);
- if i < high then
- QuickSort(arr, i, high);
- end;
- end;
- procedure StringArraySorter(var arr : wordsContainer);
- begin
- if arr.Length = 0 then
- exit;
- QuickSort(arr, 1, arr.Length);
- end;
- procedure DisplayStringArray(var arr : wordsContainer);
- var i:integer; isNotFirstDisplayingChannel : boolean;
- begin
- writeln;
- write('Words list: ');
- isNotFirstDisplayingChannel := false;
- for i:=1 to arr.Length do
- begin
- if isNotFirstDisplayingChannel then write(', ');
- write(arr.Values[i]);
- isNotFirstDisplayingChannel := true;
- end;
- end;
- BEGIN
- FillWordArray(wordsList);
- StringArraySorter(wordsList);
- DisplayStringArray(wordsList);
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement