Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Tables 1

Status
Not open for further replies.

Den1se

Programmer
Dec 8, 2005
4
0
0
GB
I urgently need help for my exam on 12/09/01. I have to sort a table described as FF-Table 10 element. Each element consists of FF-phone-num Pic x(14) and FF-cost Pic 9(6)v99. I have to sort it into descending cost but I cannot use the sort routine.
 
Do a search on BUBBLE SORT. There will be several descriptions of exactly how to do it. It is not elegant, but for a ten-item array, it is about as efficient as anything else.
Ummmmm, we don't DO your homework for you, but we are happy to show you the way.

Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at

stephenjspiro at hotmail.com
 
You can use just one table and swap the smallest element down one location till you reach the bottom. If you have 10 elements, after 9 passes the table is sorted.


Swap Process:
say yu have 3 numbers

12498<=====temp fld:________
| ^
V ^
67894 ===============>^
98012

you compare the first 2

if the first one is smaller, move the second one to a temporary field, move the first one to the second ones location, and then move the temp field to the first one's location.

If you have a large table you would want to decrease the location of the bottom of the table after every pass. If you went up and then turned around and went down you would automatically reset the counter.
If you do not like my post feel free to point out your opinion or my errors.
 
ceh4702,

that is called a bubble sort, which Stephen referred to. But, you did save Den1se a search on the web, her being out of time and all ...

Regards,
Ronald.
 
Hi,

one bubble sort example:

Code:
003000     PERFORM VARYING SUB  FROM +1 BY +1 UNTIL SUB  > T - 1 AFTER
003100                     SUB2 FROM T BY -1 UNTIL SUB2 < SUB + 1
003200         IF XT-FACTOR (SUB) > XT-FACTOR (SUB2)
003300             MOVE XT-FACTOR (SUB)  TO HELP-XT-FACTOR
003400             MOVE XT-FACTOR (SUB2) TO XT-FACTOR (SUB)
003500             MOVE HELP-XT-FACTOR   TO XT-FACTOR (SUB2)
003600         END-IF
003700     END-PERFORM.

Regards,

Crox
 
If after every pass of the sort you used display to print out the table to the screen you could watch the table entries come slowly to the top. That is why it is a bubble sort. If you do not like my post feel free to point out your opinion or my errors.
 
As an old COBOL programmer wanting to learn new tricks, I once took a Visual Basic class. One of our assignments was to write any program that used a &quot;Bubble Sort&quot;. Having implemented the algorithm in many different languages over the years, I found a way to make it interesting, although it would be hard to implement this one in COBOL:
First I put an array of randomly placed, randomly colored circles on the screen over a large greenish oval that I labelled &quot;Toxic Waste&quot;. Then I proceded to &quot;bubble sort&quot; the circles (or bubbles) by color.
I still use the program today to demonstrate the bubble sort concept in the COBOL course I teach. Betty Scherber
Brainbench MVP for COBOL II
 
Betty,

sweeet!!! I've been wondering about a way to visualize the effect of a bubble sort, but your approach must look very spectacular! Bit tricky to realise in COBOL, though...
O well, i should be having a Java class in the next couple of months, so that's a nice assignment for practice.

Regards,
Ronald.
 
Thanks, Ronald -
It was a lot more fun to write and debug than a plain old bubble-sort program. Of course, I did wind up having to put in a big delay-loop to slow it down enough so we humans could watch it happening. Betty Scherber
Brainbench MVP for COBOL II
 
Which COBOL is the student using? Some of the compilers support the sorting of a table with the SORT statement. This is a feature of the coming COBOL standard.
 
Thane,

first, 12/09/01 has long past by now; second, the original poster mentioned that she &quot;couldn't use the sort routine&quot;. I interpreted that as having to work out a sorting algorithm herself rather then using COBOL SORT, which indeed should be supported by most COBOL versions since it is part of the standard.

Regards,
Ronald.
 
12/09/01 has long past by now ????????

I must need a new calendar! :)
confusedlady
 
Hi,

here in Europe we use an other system!

DD-MM-YY format instead of MM/DD/YY

The ISO8601 standard is better:

YYYY-MM-DD

So what was ment is 2001-09-12

I hope you didn't spend your money already...

Greetings,

Crox
 
Confusedlady,

On this forum, often threads are continued just for the fun of it...

Regards,
Ronald.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top