how to sort single column in a table by shting the whole row



High Level Assembler(HLASM) for MVS & VM & VSE

how to sort single column in a table by shting the whole row

Postby sudeepth » Sun Mar 30, 2014 6:06 am

Hi Sir,
I have to bubble sort a single column in the table but need to swipe the remaining rows along with the column. How do i do that using a dsect.Please help me out.
sudeepth
 
Posts: 6
Joined: Thu Mar 13, 2014 2:13 pm
Has thanked: 1 time
Been thanked: 0 time

Re: how to sort single column in a table by shting the whole row

 

Re: how to sort single column in a table by shting the whole

Postby dick scherrer » Sun Mar 30, 2014 6:19 am

Hello,

I am not familiar with your terminology. Show an example table and how it should be processed. You need show only a Small table . . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: how to sort single column in a table by shting the whole

Postby sudeepth » Sun Mar 30, 2014 6:54 am

A $32 Dekalb
B $24 Naperville
C $2 Elburn
D $5 Chicago
E $90 Ohio

Suppose this is the table where the rows must be arranged in descending order according to the dollar value given in each row.
Please explain using bubble sort here.
sudeepth
 
Posts: 6
Joined: Thu Mar 13, 2014 2:13 pm
Has thanked: 1 time
Been thanked: 0 time

Re: how to sort single column in a table by shting the whole

Postby dick scherrer » Sun Mar 30, 2014 7:10 am

Hello,

You Do know how to code a bubble sort, right? There are examples many places if not.

For your request, I would "normalize" the amounts so they will all be aligned.
Then i would use the width of the amount as my sort key and work entries that were the full width of a table entry.

After the array is in order, do whatever is needed - print the new array, apply it to some process (not considered here), whatever.

Good luck :)

d
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: how to sort single column in a table by shting the whole

Postby steve-myers » Sun Mar 30, 2014 9:28 pm

You have not bothered to tell us two very important things: are you "sorting" an array of pointers to table entries or are you "sorting" an array of table entries, and, are you sorting so the final product will be arranged in ascending order or descending order. I usually "sort" an array of pointers; it's slightly more efficient; exchanging two 4 byte pointers is faster than exchanging two large table entries.

In any event, you need a DSECT for your table entries, for example:
ENTRY    DSECT
COL1     DS    CL4
COL2     DS    F
COL3     DS    CL16
ENTSIZE  EQU   *-ENTRY
In any event, you will wind up with 2 registers pointing to different table entries. Since you appear to be sorting based on a value, you write something like this for ascending order:
         L     0,COL2-ENTRY(,reg1)
         C     0,COL2-ENTRY(,reg2)
         BNH   REG1LOW
* Exchange the entries here
REG1LOW  ...
There are other ways to do this, of course, but the example will work with all Assemblers.

Good luck.
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: how to sort single column in a table by shting the whole

Postby steve-myers » Mon Mar 31, 2014 8:13 pm

Just for the H of it I did your homework assignment. Now, I'm not going to show any code, but I will discuss the method.

Input
A  32 DEKALB   
B  24 NAPERVILLE
C   2 ELBURN   
D   5 CHICAGO   
E  90 OHIO     
I removed the $ in the second column, and to simplify the code I made all three columns fixed width.

Data area definitions -

Input
IENTRY   DSECT     
COL1     DS    CL2
COL2     DS    CL3
COL3     DS    CL10


Intermediate storage
SENTRY   DSECT         
SENEXT   DS    A       
SCOL1    DS    CL2     
SCOL2    DS    PL2     
SCOL3    DS    CL16   
SESIZE   EQU   *-SENTRY

Since I didn't know how many input records I'd be reading, I defined them as a linked list: SENEXT points to the next entry. I also made column 2 packed decimal to simplify the compare in the sort code.

I also chose to "sort" an array of pointers.

The program reads the input data, allocates storage for each SENTRY, copies COL1 and COL3 in the input to SCOL1 and SCOL3, and converts the zoned decimal COL2 to the packed decimal SCOL2.

At the end of data, the program builds an array of pointers to each of the SENTRY DSECTs built in the input, and "sorts" the array of pointers.

After the sort, it converts each SENTRY to a print line:
E   90  OHIO     
A   32  DEKALB   
B   24  NAPERVILLE
D    5  CHICAGO   
C    2  ELBURN   
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: how to sort single column in a table by shting the whole

Postby steve-myers » Thu Apr 03, 2014 11:57 pm

Now I don't think you realized this, but this homework assignment (and the tasks in How to replace XDECI using PACK and CVB?) include
  • Parsing data in input data.
  • Sorting data.
  • Simple data conversion.
  • Printing data.
All of this is basic to the work Assembler programmers (as well as programmers in other languages) do regularly.
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times


Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post