Free Tutorials, Linux Command, Source Code Architecture,  Software Engineering, Intelligent Systems, RDBMS, Computer Accounting,  Operations Research, Discrete Mathematics, Network, SAD Lay Networks Lay Networks
Computer Science Networking Operating Systems Linux and Unix Source Code Script & Languages Protocols Glossary
Web laynetworks.com
Google
 


Write a programme in COBOL for sorting an array using any sorting procedure.
Contributed by Malisetty Siva Sankar


ALGORITHM :

Use of this method results in the first part of the table being sorted by first. By the bubble sort-interchange method the first step is that the second record is compared with the first, and if necessary they are interchanged.

Then the third record is compared with second. If these two records are interchanged the (new) second record is compared with the first, interchanging if necessary.

Next the fourth and third records are compared for possible interchange. Again if an interchange occurs, we go " upward" and compare the third with second record and then possibly to find its proper place, and hence the name "bubble sort" which is applied to this algorithm.

As an example of using the bubble sort interchange algorithm, consider the following set of six records with sort key as indicated.

15
18
20
21
19
25

Comparison of the second and first records results in no change. Similarly comparison of the third and second and of fourth and third records results in no interchange. However, when the fifth and fourth records are compared (19 and 21) an interchange results. Following this comparison of fourth and third (19 and 20 ) results in an interchange, but then the comparison of the third and second records are compared (25 and 21. Since his is last pair of records and no interchange is required, thus sort routine is completed.


CODE:

IDENTIFICATION DIVISION.
PROGRAM-ID.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 N PIC 999.
77 I PIC 999.
77 J PIC 999.
77 K PIC 999.
77 TEMP PIC 999.
77 D PIC X.
01 AAA.
02 A PIC 999 OCCURS 100 TIMES.
PROCEDURE DIVISION.
MAIN.
DISPLAY (1 1) ERASE.
DISPLAY (10, 5) "ENTER HOW MANY NUMBER YOU WANT TO ENTER".
ACCEPT (10, 50) N WITH PROMPT.
DISPLAY (1 1) ERASE.
DISPLAY (6, 30) "INPUT THE NUMBERS".
MOVE 6 TO LIN.
PERFORM ACC-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
PERFORM BUB-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
DISPLAY (1 1) ERASE.
DISPLAY (5, 30) "OUTPUT (BUBBLE SORT)".
DISPLAY (6, 30) "~~~~~~ ~~~~~~ ~~~~".
MOVE 6 TO LIN.
PERFORM DIS-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
STOP RUN.

ACC-PARA.
COMPUTE LIN = LIN + 1.
ACCEPT (LIN, 35) A(I) WITH PROMPT.
IF LIN = 20
DISPLAY (1 1) ERASE
DISPLAY (6, 30) "CONTINUE"
MOVE 6 TO LIN.

BUB-PARA.
COMPUTE K = I + 1.
PERFORM BUB1-PARA VARYING J FROM K BY 1 UNTIL J > N.


BUB1-PARA.
IF A(I) > A(J)
MOVE A(I) TO TEMP
MOVE A(J) TO A(I)
MOVE TEMP TO A(J).

DIS-PARA.
COMPUTE LIN = LIN + 1.
DISPLAY (LIN, 33) A(I).
IF LIN = 20
DISPLAY (24, 30) "PRESS ANY KEY"
ACCEPT D
DISPLAY (1 1) ERASE
MOVE 6 TO LIN.

Output

MAIN MENU

ENTER HOW MANY NUMBER YOU WANT TO ENTER…….6

SUBMENU

INPUT THE NUMBERS

15
18
20
21
19
25

OUTPUT (BUBBLE SORT)

-----------------------------------

15
18
19
20
21
25


 

Top

Back
FDDI Frequently Asked Questions (FAQ), The function and frame format of FDDI,Aloha,Comparative analysis between two types of ATM Switches,Knockout Switch,Barcher-Banyan Switch,Various popular standards for compressing multimedia data,Distributed Multimedia Survey: Standards, ASCII to hex value chart,Comparative analysis - TCP - UDP, Addressing Formats and QoS parameters, Bellman Ford's Algorithm Lay networks, free, java, java script, asp, vb, linux, ignou, tutorial, Unix commands, System Analysis, System Design, Ipv6, quiz, download, free, Computer Architecture, Object Oriented System, Relational Database Management Systems, Object Oriented System, Operating Systems, Software Engineering, Communications and Networks, Discrete Mathematics, Intelligent Systems, Operations Research, Accounting and Finance on Computersmca, networking, protocols, glossary, assignment, project, tma, programming source code, programming, source code, unix, free
 
Book Mark/Share this site at BlinkBits BlinkList Blogmarks co.mments Delicious Digg Fark Furl it! Google Ma.gnolia Netvouz NewsVine RawSugar Reddit Shadows Simpy Stumble Technorati YahooMyWeb

Copyright © 2000- 2007 Lay Networks All rights reserved. 
This website is best viewed in Firefox 1.0.1 above.

Web Hosting sponsored by Customized Software Company India
Web Site Designed by Web Designing, Flash Animation, Multimedia Presentations, Broacher/catalogue designing, Web Promotion 
Refer to your freind About Us Legal IGNOU Contact Us Feedback Donate to laynetworks.com Download Management Tutorials Tutorials History Search here