/* rexx */ /*-------------------------------------------------------------------*/ /* */ /* REXX Exec : SORTDEMO */ /* */ /* Description : Demonstration of sorting an array */ /* */ /* Created on : 14 Jul 2023 */ /* Created by : Wendy Miller */ /* : Userid MIT002 */ /* : Using ABBYDALE.DEVL.REXX(SORTDEMO) */ /* */ /* Called by : Nothing */ /* */ /* Calls : Nothing */ /* */ /* Panels Used : None */ /* */ /* Change Activity : */ /* */ /* ©Copyright of Abbydale Systems LLC. */ /* */ /*-------------------------------------------------------------------*/ /* First build your array */ call BuildArray lx = 8 /* Number of elements in array */ /* Now show the original array */ say '-- Unsorted Table --' Do x = 1 to lx say Linkmod.x 'is used via a 'LinkHow.x End /* Sort the table */ do k = 1 to lx -1 do r = k+1 to lx k_Linkmod = linkmod.k k_Linkhow = linkhow.k r_Linkmod = linkmod.r r_Linkhow = linkhow.r if r_Linkmod < k_Linkmod then do Linkmod.k = r_Linkmod Linkhow.k = r_Linkhow Linkmod.r = k_Linkmod Linkhow.r = k_Linkhow end end end say ' ' say ' ' /* Now show the sorted array */ say '--- Sorted Table ---' Do x = 1 to lx say Linkmod.x 'is used via a 'LinkHow.x End call BuildArray /* Rebuild the array */ /* Sort the table on both fields */ do k = 1 to lx -1 do r = k+1 to lx k_Linkmod = linkmod.k k_Linkhow = linkhow.k r_Linkmod = linkmod.r r_Linkhow = linkhow.r if r_Linkmod < k_Linkmod then do Linkmod.k = r_Linkmod Linkhow.k = r_Linkhow Linkmod.r = k_Linkmod Linkhow.r = k_Linkhow end if r_Linkmod = k_Linkmod then do if r_Linkhow < k_Linkhow then do Linkmod.k = r_Linkmod Linkhow.k = r_Linkhow Linkmod.r = k_Linkmod Linkhow.r = k_Linkhow end end end end say ' ' say ' ' /* Now show the sorted array */ say '-- Table Sorted on both Fields --' Do x = 1 to lx say Linkmod.x 'is used via a 'LinkHow.x End Exit BuildArray: /* Here is where we build our demonstration array. Each array item will have two fields. You can add additional fields if needed i.e fred.1 */ Linkmod.1 = 'IEBCOPY' LinkHow.1 = 'Call' Linkmod.2 = 'ASLCOPY' LinkHow.2 = 'Link' Linkmod.3 = 'WHATNAME' LinkHow.3 = 'Link' Linkmod.4 = 'WHATNAME' LinkHow.4 = 'Call' Linkmod.5 = 'IEBUPDTE' LinkHow.5 = 'Call' Linkmod.6 = 'ASLDEL' LinkHow.6 = 'Call' Linkmod.7 = 'ASLQWTO' LinkHow.7 = 'Attach' Linkmod.8 = 'MQERROR' LinkHow.8 = 'LOad' return /*-------------------------------------------------------------------*/ /* End of SORTDEMO */ /*-------------------------------------------------------------------*/