Quicksort Routine(Architecture Cont.)
file_open(fresult,in_fd,infile,READ_MODE);
IF(fresult /= OPEN_OK) THEN
REPORT "Usage: qvsim qsort
FILE_OPEN(fresult,out_fd,outfile,WRITE_MODE);
IF(fresult /= OPEN_OK) THEN
REPORT "Usage: qvsim qsort
-- read in file and set number of elements
WHILE(NOT ENDFILE(in_fd)) LOOP
READ(l,iarray(nelements));
nelements := nelements + 1;
-- find minimum element and place in
-- element zero for sentinel
FOR i IN 1 TO nelements - 1 LOOP
IF(iarray(i) < tempint) THEN
IF(temppointer /= 0) THEN
iarray(temppointer) := iarray(0);
quicksort(iarray,0,nelements-1);
FOR i IN 0 TO nelements - 1 LOOP
Notes:
This is the main part of the architecture. It reads in the integer array data from a file, finds the minimum (least) element and puts in in element 0 as a sentinel (required by the quicksort routine) calls quicksort on the entire array, and then writes the result back out to a file.