;Demonstration of a Bubble Sort using arrays PW2.0 ;*********************************************************************** ;* * ;* ARRAY.WAS * ;* Copyright (C) 1994 Datastorm Technologies, Inc. * ;* All rights reserverd. * ;* Written by: Ken McMinn * ;* * ;* PURPOSE: * ;* The purpose of this script is to demonstrate how to sort integers in* ;* ascending order using a bubble sort. * * ;* * ;* This Windows ASPECT SCRIPT is intended only as a sample of ASPECT * ;* programming. DATASTORM makes no warranty of any kind, express or * ;* implied, including without limitation, any warranties of * ;* merchantability and/or fitness for a particular purpose. Use of * ;* this program is at your own risk. * ;*********************************************************************** ;*********************************************************************** ;* MACRO DEFINITIONS * ;*********************************************************************** #define SIZE 10 ;*********************************************************************** ;* GLOBAL VARIABLES * ;*********************************************************************** integer Array[SIZE] ;*********************************************************************** ;* * ;* MAIN() * ;* The main procedure shows how to put integers in an array and sort * ;* them in ascending order. * ;* * ;* Calls: PutInArray, PrintOriginal, SortArray, PrintAscending * ;* Modifies globals: none * ;* * ;*********************************************************************** proc Main PutInArray() ;proc to put integers in array PrintOriginal() ;proc to print orginal order SortArray() ;proc to sort array PrintAscending() ;proc to print sorted order endproc ;*********************************************************************** ;* * ;* PUTINARRAY() * ;* The procedure enters numbers into an array to be sorted * ;* * ;* Calls: none * ;* Called From: Main * ;* Modifies globals: Array[] * ;* * ;*********************************************************************** proc PutInArray array[0] = 2 ;put numbers in array array[1] = 6 array[2] = 4 array[3] = 8 array[4] = 12 array[5] = 10 array[6] = 89 array[7] = 68 array[8] = 45 array[9] = 37 endproc ;*********************************************************************** ;* * ;* PRINTORIGINAL() * ;* The procedure prints orginal order of the array to the terminal. * ;* * ;* Calls: none * ;* Called From: Main * ;* Modifies globals: none * ;* * ;*********************************************************************** proc PrintOriginal integer I termmsg "`r`nHere is the array in original order`r`n" ;print to screen for I = 0 upto (SIZE - 1) ;loop until end of array termmsg "%d " Array[I] ;print value to screen endfor ;endloop endproc ;*********************************************************************** ;* * ;* SORTARRAY() * ;* The procedure sorts the array in ascending order. * ;* * ;* Calls: none * ;* Called From: Main * ;* Modifies globals: Array[] * ;* * ;*********************************************************************** proc SortArray integer Pass, HoldIt, I for Pass = 1 upto (SIZE - 1) ;continue until end of array for I = 0 upto (SIZE - 2) if (Array[I] > Array[I + 1]) ;compare positions of array HoldIt = Array[I] ;hold integer into hold value Array[I] = Array[I + 1] ;put smaller integer into lower spot Array[I + 1] = HoldIt ;put hold integer into higher spot endif endfor endfor endproc ;*********************************************************************** ;* * ;* PRINTASCENDING() * ;* The procedure prints the order of array to the terminal screen. * ;* * ;* Calls: none * ;* Called From: Main * ;* Modifies globals: none * ;* * ;*********************************************************************** proc PrintAscending integer I termmsg "`r`nHere they are in ascending order`r`n" ;msg to user for I = 0 upto (SIZE - 1) ;loop until end of array termmsg "%d " Array[I] ;print value to screen endfor ;endloop endproc