/* Sorting using N-squared algorithms */ Parse Arg N If N="" then Do Say "How many numbers to sort?" Parse Pull N end /* do */ /* Generate some random numbers */ Do i=1 to N x.i=Random(0,N) x2.i=x.i end /* do */ x.0=N /* Call the bubble sort routine */ elapsed=BubbleSort() Say "Bubble sort took" elapsed "seconds." Call ResetItems /* Call the straight insertion sort routine */ elapsed=InsertionSort() Say "Insertion sort took" elapsed "seconds." Call ResetItems /* Call the modified insertion sort routine */ elapsed=ModifiedInsertionSort() Say "Modified insertion sort took" elapsed "seconds." Exit BubbleSort: Procedure Expose x. start=Time("R") do i = x.0 to 1 by -1 until sorted = 1 sorted = 1 do j = 2 to i m = j - 1 if x.m > x.j then do a=x.m x.m=x.j x.j=x sorted=0 end /* do */ end /* do */ end /* do */ end=time("R") elapsed=end-start Return elapsed InsertionSort: Procedure Expose x. start=Time("R") Do i=1 to x.0-1 Do j=i+1 to x.0 If x.j