[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Everything about COBOL
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
  Sorting in REXX: The Bubble Sort
  REXX Password Generator
  Using REXX to capture displayed output of TSO command
  Count records in REXX
  REXX program to calculate present value of money
  REXX function to format a number in currency format
  REXX function to produce a fixed-length number
  REXX program to produce lottery numbers
  REXX: what does your phone number spell?
  REXX Practice Problems.
  Just Enough REXX Tutorial
  Setting up to Execute REXX Programs on TSO/ISPF
  How to execute a REXX program
  REXX Boolean operators
  Comparison of CLIST language and REXX
  REXX Comparison operators
  REXX Debugging: the TRACE verb
  Using REXX OUTTRAP
  Reserved REXX Variables
  Executing REXX through JCL.
  Writing ISPF Edit Macros in REXX
  REXX program to unload a PDS
  REXX book: The REXX Language on TSO
  REXX Functions Book
  QMF Procedures Written in REXX
  Using REXX Subroutines with the QMF Calc panel
  REXX error codes (RC)
  REXX programming language manuals
  Books on REXX programming
  The REXX Files
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > REXX   > REXX Bubble Sort

Sorting in REXX: The Bubble Sort

How you can sort small amounts of data with REXX. This technique uses much more CPU time for large amounts of data.
/*rexx program bubbsort. it illustrates a bubble sort */

/* load the array 
   may also be loaded by execio, or a call outtrap
*/
name.1 = "marie"
name.2 = "beth"
name.3 = "linda"
name.4 = "maria"
name.5 = "nadia"
name.6 = "angela"
name.7 = "michelle"
count_of_elements = 7

/* loop through the array (count_of_elements - 1) ** 2 times */
do i = 1 to  (count_of_elements - 1)
   do j = 1 to (count_of_elements - 1)
      j_plus1 = j + 1
      /* if an element is greater than the next one higher, 
         interchange them */
      if name.j > name.j_plus1 then call flipem
   end j
end i

/* show results*/
do i = 1 to count_of_elements
   say name.i
end i

exit

flipem:
/* reverse the order of the two elements */
temp = name.j
name.j = name.j_plus1
name.j_plus1 = temp
return

Learn how to use all the features of REXX: REXX Programming Book for TSO (published 2012)

[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |