verilog code to find max and min in an input signal..

I want to find max and min in input file, read from a memory. This input file containsize 1000 decimal sample values. I have written the following code to find max and min by comparing with a threshold.

module max_min(input clk, input [15:0]din, output [15:0]dout);
reg [15:0]max=0;
reg [15:0]min=0;
always @(posedge clk) begin
else if($signed(din)<min)
assign dout=max;`
The problem in above code is that for example the if condition becomes true for (eg) the 2nd cycle sample value, then max will be assigned the 2nd sample value as max sample value. Now let us consider that input din has max sample value at the 15th cycle of all the 1000 samples. So after the 15th cycle max will contain that max value and the output dout will contain max value after 15th cycle and before 15th cycle it will contain the maximum of the first 14 sample values. I want my output i.e max register to contain only the maximum value i.e the 15th value.

verilog system-verilog