## How to Implement Bubble sort in Cobol ??

Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

### How to Implement Bubble sort in Cobol ??

i/p : S.no , Name , mark1 , mark2 , mark3

o/p : S.no , Name , mark1 , mark2 , mark3 , Average , Rank

I want to sort as per Rank .(Highest one at top )

There are many method to solve this . but i need to find thru Cobol .

Gautham
gauthamnagpur18

Posts: 93
Joined: Sat Oct 23, 2010 1:28 pm
Location: Chennai, India
Has thanked: 3 times
Been thanked: 2 times

### Re: How to Implement Bubble sort in Cobol ??

Hello,

Take any pseudo-code you have found and write this in cobol. All you should need is an array and a loop. . .

We will help if/when you get stuck, but will not do the work for you.
Hope this helps,
d.sch.

dick scherrer
Global moderator

Posts: 6308
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 90 times

### Re: How to Implement Bubble sort in Cobol ??

To make your life almost tolerable, Gautham, here is the pseudo-code for bubble sort, a discussion of why you shouldn't use it, and links to other sort algorithms.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day

Akatsukami
Global moderator

Posts: 995
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 48 times

### Re: How to Implement Bubble sort in Cobol ??

why not use internal sort

Surely this sort of code is done as student exercises in cobol intro courses I know it was for us 30 years ago.

SUrely learning for yourself is a better way to becoming an expert programmer not he 95% who are not so good coders.
littlechicken

Posts: 25
Joined: Thu Oct 28, 2010 10:15 am
Has thanked: 0 time
Been thanked: 0 time

### Re: How to Implement Bubble sort in Cobol ??

if fact why not do both as an exercise write a array bubble sort then also write the code to sort it as an internal sort

that way you get to learn both ways.

even smarter see if you can do the sort call and use the compile option to use internal cobol sort or external DFSORT/SYNCSORT.

have fun learning its better than being given the code.
littlechicken

Posts: 25
Joined: Thu Oct 28, 2010 10:15 am
Has thanked: 0 time
Been thanked: 0 time

### Re: How to Implement Bubble sort in Cobol ??

Hello,

why not use internal sort
Because the requirement is to write the cobol code for a bubble sort. . .
Hope this helps,
d.sch.

dick scherrer
Global moderator

Posts: 6308
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 90 times

### Re: How to Implement Bubble sort in Cobol ??

dick scherrer wrote:Hello,

why not use internal sort
Because the requirement is to write the cobol code for a bubble sort. . .

Is it? I grant that the thread's title is "How to Implement Bubble sort in Cobol??", but the OP seems to suggest that any algorithm is acceptable so long as it is implemented in COBOL. Invoking DFSORT/SyncSort via the COBOL SORT verb probably doesn't fulfill the requirement, but it seems to me that there are a lot of algorithms besides bubble sort that do.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day

Akatsukami
Global moderator

Posts: 995
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 48 times

### Re: How to Implement Bubble sort in Cobol ??

Hello,

but it seems to me that there are a lot of algorithms besides bubble sort that do
Yup, but this seems to have lasted in many training facilities - probably because it is already "there". . .

The link Akatsukami posted also mentions why bubble sort is not a good choice:
here is the pseudo-code for bubble sort, a discussion of why you shouldn't use it, and links to other sort algorithms.
Hope this helps,
d.sch.

dick scherrer
Global moderator

Posts: 6308
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 90 times

### Re: How to Implement Bubble sort in Cobol ??

Thanks all for suggesting ideas . I have completed till calculation of average .Now i dunno how to go forward ??
gauthamnagpur18

Posts: 93
Joined: Sat Oct 23, 2010 1:28 pm
Location: Chennai, India
Has thanked: 3 times
Been thanked: 2 times

### Re: How to Implement Bubble sort in Cobol ??

Hello,

I have completed till calculation of average .
What does this mean?

You need to provide the detail of what you have done, what you are doing, and where/why you are stuck.
Hope this helps,
d.sch.

dick scherrer
Global moderator

Posts: 6308
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 90 times

Next