;Demonstration of a BUBBLE SORT using arrays v1.10

;* Written by:  Symantec ASPECT Assist                                       *
;*                                                                           *                                                                             
;* This script file will give the user the option of either capturing data   *
;* in half hour increments, or in 24 hour increments. The Capture file will  *
;* close after a predefined period of inactivity on the port.                *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec 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.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************




;***********************************************************************
;*   MACRO DEFINITIONS                                                 *
;***********************************************************************

#define ArraySIZE 10 



;***********************************************************************
;*   GLOBAL VARIABLES                                                  *
;***********************************************************************

integer TheArray[ArraySIZE]
 
 
 
;***********************************************************************
;*                                                                     *   
;* 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: TheArray[]                                        *     
;*                                                                     * 
;*********************************************************************** 
proc PutInArray                                                                                                          
   TheArray[0] = 2              ;put numbers in array                                                                                        
   TheArray[1] = 6                                                                                            
   TheArray[2] = 4                                                                                            
   TheArray[3] = 8                                                                                            
   TheArray[4] = 12
   TheArray[5] = 10                                                                                           
   TheArray[6] = 89                                                                                           
   TheArray[7] = 68                                                                                           
   TheArray[8] = 45                                                                                           
   TheArray[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 (ArraySIZE - 1)                        ;loop through array                       
      termmsg "%d " TheArray[I]                          ;print to screen                                                
   endfor                                                ;endloop
endproc


 
;***********************************************************************
;*                                                                     *   
;* SORTARRAY()                                                         * 
;* The procedure sorts the array in ascending order.                   *
;*                                                                     *
;* Calls: none                                                         *
;* Called From:  Main                                                  *      
;* Modifies globals: TheArray[]                                        *     
;*                                                                     * 
;***********************************************************************
proc SortArray
integer Pass, HoldIt, I
                                                                                                          
   for Pass = 1 upto (ArraySIZE - 1)        ;loop until end of array                            
      for I = 0 upto (ArraySIZE - 2)                                                 
         if (TheArray[I] > TheArray[I + 1]) ;compare element positions                            
            HoldIt = TheArray[I]            ;hold the array integer                                                      
            TheArray[I] = TheArray[I + 1]   ;put smaller integer lower                                                      
            TheArray[I + 1] = HoldIt        ;put hold integer higher                                                      
         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 (ArraySIZE - 1)                      ;loop until end                         
      termmsg "%d " TheArray[I]                        ;print to screen                                                   
   endfor                                              ;endloop
endproc  