Mainframes, MVS, zOS and Related Languages Support Forums Help & Support Forum for and by Mainframe Users 2013-08-03T20:51:28+00:00 http://www.ibm-mainframes.com/feed.php?f=55 2013-08-03T20:51:28+00:00 2013-08-03T20:51:28+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=316&p=716#p716 <![CDATA[Programming Algorithms. • Bubble Sort.]]> Bubble Sort:The bubble sort is generally considered to be the simplest sorting algorithm. The bubble sort works by passing sequentially over a list, comparing each value to the one immediately after it. If the first value is greater than the second, their positions are switched. Over a number of passes, at most equal to the number of elements in the list, all of the values drift into their correct positions (large values "bubble" rapidly toward the end, pushing others down around them). Because each pass finds the maximum item and puts it at the end, the portion of the list to be sorted can be reduced at each pass. A boolean variable is used to track whether any changes have been made in the current pass; when a pass completes without changing anything, the algorithm exits.

Why is it called a bubble sort?The bubble sort gets its name because elements tend to move up into the correct order like bubbles rising to the surface.


Pseudocode
Code:
loop
    NewValue := false
    decrement itemCount
    loop with index from 1 to itemCount
        if (item at index) > (item at (index + 1))
            swap (item at index) with (item at (index + 1))
            NewValue := true
until NewValue = false


There can be many implementation of this in COBOL, one such is as follows:

Code:
IDENTIFICATION DIVISION.
        PROGRAM-ID. PRG1.
       DATA DIVISION.
           01 TABLE OCCURS 5 TIMES PIC S9(2).
           01 TEMP PIC 999 VALUE 000.
           01 VAR1 PIC 9 VALUE 0.
           01 VAR2 PIC 9 VALUE 1.
       PROCEDURE DIVISION.
       0000-HOUSEKEEPING.
           DISPLAY "ENTER ANY FIVE NUMBERS:"
*
           PERFORM UNTIL VAR1 = 5
           ADD 1 TO VAR1 
           ACCEPT TABLE(VAR1)
           END-PERFORM.
*
           MOVE 1 TO VAR1.
*
           PERFORM UNTIL VAR1 > 5
                        MOVE VAR1 TO VAR2
                        PERFORM UNTIL VAR2 > 5
                                     IF (TABLE(VAR1) > TABLE(VAR2))
                                        MOVE TABLE(VAR1) TO TEMP
                                        MOVE TABLE(VAR2) TO TABLE(VAR1)
                                        MOVE TEMP TO TABLE(VAR2)
                                     END-IF
                        ADD 1 TO VAR2 GIVING VAR2
                       END-PERFORM
*
           ADD 1 TO VAR1 GIVING VAR1
           END-PERFORM.
*
           MOVE 0 TO VAR1.
*
           PERFORM UNTIL VAR1 = 5
           ADD 1 TO VAR1 
           DISPLAY  VAR1 ":=" TABLE(VAR1)
           END-PERFORM.
*       
GOBACK.

Output:
Code:
    ENTER ANY FIVE NUMBERS:
    98
    25
    54
    55
    22

    AFTER SORTING:
    22
    25
    54
    55
    98

Statistics: Posted by Anuj Dhawan — Sat Aug 03, 2013 8:51 pm


]]>
2013-07-26T12:53:02+00:00 2013-07-26T12:53:02+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=256&p=622#p622 <![CDATA[Programming Algorithms. • Re: We made a Century!!]]> Making Century is a history now -- We made Much More than a Double Century!

script
Most users ever online was 250 on 26 Jul 2013
script 01:01


What are you waiting for -- come get along with this busy community to clear, debate and discuss your doubts on IBM Mainframes, MVS, zOS and related Languages.

Statistics: Posted by Anuj Dhawan — Fri Jul 26, 2013 12:53 pm


]]>
2013-07-26T04:48:11+00:00 2013-07-26T04:48:11+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=295&p=619#p619 <![CDATA[Programming Algorithms. • "Report This Post" is activated.]]>
The "Report This Post Button" can be found as the first button with exclamation sign ("!"), at bottom right of any post. The pictorial representation is shown below:

Statistics: Posted by Anuj Dhawan — Fri Jul 26, 2013 4:48 am


]]>
2013-07-19T19:11:01+00:00 2013-07-19T19:11:01+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=256&p=532#p532 <![CDATA[Programming Algorithms. • Re: We made a Century!!]]>
Today it is 165!!!

Statistics: Posted by Anuj Dhawan — Fri Jul 19, 2013 7:11 pm


]]>
2013-07-18T05:35:38+00:00 2013-07-18T05:35:38+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=256&p=507#p507 <![CDATA[Programming Algorithms. • We made a Century!!]]>

We got 121 users online Yesterday, on 17 Jul 2013 at 22:54. You can check that at the bottom of Board Index. This will be shown like this: "Most users ever online was 121 on 17 Jul 2013 22:54".

That's a great achievement.

Thanks for Liking and showing the trust in to the Labor we're putting in, much appreciate that,

Thanks,

Statistics: Posted by Anuj Dhawan — Thu Jul 18, 2013 5:35 am


]]>
2013-07-05T06:39:21+00:00 2013-07-05T06:39:21+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=207&p=328#p328 <![CDATA[Programming Algorithms. • What is this Forum about?]]>
The best definition of an algorithm I've heard is that it is a finite sequence of steps that solves a specific problem.

This Forum is about listing out such algorithms - irrespective of what programming language you code in.

Name the algorithm - tell about it in plain-english and possibly, you can show its implementation if you want to.

Statistics: Posted by Anuj Dhawan — Fri Jul 05, 2013 6:39 am


]]>
2013-06-17T05:48:23+00:00 2013-06-17T05:48:23+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=164&p=230#p230 <![CDATA[Programming Algorithms. • AJAX Chat is Installed!]]> AJAX Chat is Installed! Using this you can Chat with other registered members while you're logged in -- it's Fun when you don't to post a topic however, still want to convey some message to other user. Below is a handy link to AJAX Chat corner. You can also find it on the "Menu-Bar" adjacent to FAQ.


AJAX Chat


For the Curious minds: Ajax Chat is a high performance php-based chat server software for a live chat-room or -module on every php-based site.

Statistics: Posted by Anuj Dhawan — Mon Jun 17, 2013 5:48 am


]]>
2013-06-16T14:58:13+00:00 2013-06-16T14:58:13+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=163&p=229#p229 <![CDATA[Programming Algorithms. • Arcade Games are Installed!]]> Arcade Games are Installed! So have Fun while You Learn! :)

There are currently 25 games installed. Have a look: Here is a list of Games - click on Arcade below to get started:

Arcade

And don't Forget to Submit Your highest Score!

Statistics: Posted by Anuj Dhawan — Sun Jun 16, 2013 2:58 pm


]]>
2013-06-13T06:20:07+00:00 2013-06-13T06:20:07+00:00 http://www.ibm-mainframes.com/viewtopic.php?t=118&p=208#p208 <![CDATA[Programming Algorithms. • Re: Mobile View.]]>

Statistics: Posted by Admin — Thu Jun 13, 2013 6:20 am


]]>