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 ??

Postby gauthamnagpur18 » Tue Nov 23, 2010 1:01 am

I got one task :

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 .

Thanks in advance
Gautham
gauthamnagpur18
 
Posts: 93
Joined: Sat Oct 23, 2010 1:28 pm
Location: Chennai, India
Has thanked: 3 times
Been thanked: 3 times

Re: How to Implement Bubble sort in Cobol ??

Postby dick scherrer » Tue Nov 23, 2010 1:20 am

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.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: How to Implement Bubble sort in Cobol ??

Postby Akatsukami » Tue Nov 23, 2010 2:51 am

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
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: How to Implement Bubble sort in Cobol ??

Postby littlechicken » Tue Nov 23, 2010 6:49 am

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 ??

Postby littlechicken » Tue Nov 23, 2010 6:51 am

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 ??

Postby dick scherrer » Tue Nov 23, 2010 9:21 am

Hello,

why not use internal sort
Because the requirement is to write the cobol code for a bubble sort. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: How to Implement Bubble sort in Cobol ??

Postby Akatsukami » Tue Nov 23, 2010 9:08 pm

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
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: How to Implement Bubble sort in Cobol ??

Postby dick scherrer » Wed Nov 24, 2010 2:52 am

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.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: How to Implement Bubble sort in Cobol ??

Postby gauthamnagpur18 » Wed Nov 24, 2010 11:56 pm

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: 3 times

Re: How to Implement Bubble sort in Cobol ??

Postby dick scherrer » Thu Nov 25, 2010 2:01 am

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.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post