Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- numberArray = array of integer;
- function sort(data: numberArray; reverse: boolean): numberArray; // bubble sort the numbers
- var
- t: array[0..1] of integer;
- i, j: integer;
- begin
- j := 0;
- while j < lines do begin
- for i := 1 to (lines - j) do begin
- if reverse = false then begin // least to greatest
- if data[i-1] > data[i] then begin
- t[0] := data[i];
- t[1] := data[i-1];
- data[i-1] := t[0];
- data[i] := t[1];
- end;
- end
- else begin // greatest to least
- if data[i-1] < data[i] then begin
- t[0] := data[i];
- t[1] := data[i-1];
- data[i-1] := t[0];
- data[i] := t[1];
- end;
- end;
- end; //for
- j := j+1;
- end; // while
- sort := data;
- end;
- function mode(data: numberArray): integer;
- var
- i, j, max, value: integer;
- tally: numberArray;
- begin
- max := 0; value := 0;
- data := sort(data, true);
- setLength(tally, data[1]);
- for i := 1 to length(data) do
- tally[data[i]] := tally[data[i]];
- for j := 1 to length(data) do begin
- if(tally[j] > max) then begin
- max := tally[j];
- value := j;
- end;
- end;
- mode := value;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement