Bubble Sort

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
bdixon
Participant
Posts: 35
Joined: Thu Nov 20, 2003 5:45 pm
Location: Australia, Sydney

Bubble Sort

Post by bdixon »

Hi All,

Does anyone have an example of a bubble sort in a before subroutine?

Brad
mchaves
Participant
Posts: 50
Joined: Mon Aug 08, 2005 9:59 pm
Location: Sydney
Contact:

Re: Bubble Sort

Post by mchaves »

bdixon wrote:Hi All,

Does anyone have an example of a bubble sort in a before subroutine?

Brad
Hi Brad,

Why do you need a bubble sort procedure? I mean, could you clarify your need a bit more?
bdixon
Participant
Posts: 35
Joined: Thu Nov 20, 2003 5:45 pm
Location: Australia, Sydney

Post by bdixon »

I have an array in a before subroutine that needs to be sorted before i save it out to a file eg
Array<1> = 123
Array<2> = 99
Array<3> = 125

I want to sort the array in the following way:
Array<1> = 99
Array<2> = 123
Array<3> = 125
clarcombe
Premium Member
Premium Member
Posts: 515
Joined: Wed Jun 08, 2005 9:54 am
Location: Europe

Post by clarcombe »

Hello,

You will have to write a before stage routine that works in the following way

0037 procedure BubbleSort( ListToSort : in out Lists) is
0038
0039 ListIsSorted : BOOLEAN := FALSE;
0040
0041 begin -- BubbleSort
0042 while not( ListIsSorted) loop
0043 ListIsSorted := TRUE;
0044 for ThisIndex in ListToSort'FIRST ..
0045 Indexes'PRED( ListToSort'LAST) loop
0046 if not SortRelation( ListToSort( ThisIndex),
0047 ListToSort( Indexes'SUCC( ThisIndex))) then
0048 Swap( ListToSort( ThisIndex),
0049 ListToSort( Indexes'SUCC( ThisIndex)) );
0050 ListIsSorted := FALSE;
0051 end if;
0052 end loop;
0053 end loop;
0054 end BubbleSort;

This is pseudocode not Datastage Basic

Good luck
Colin Larcombe
-------------------

Certified IBM Infosphere Datastage Developer
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

How are the input data being delivered?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dzdiver
Participant
Posts: 36
Joined: Tue May 25, 2004 8:55 am
Location: global

Post by dzdiver »

Does it need to be a bubble sort for some reason?

Windows has built in sort filter command.

If you had your array in a file (or put it in one) like infile.txt...

You could have a prejob something like: -
sort < infile.txt > sortedfile.txt

Then in your job, pick up the sequential file sortedfile.txt

sort also has ability to take some parameters.
Below is a copy from help file about sort command.
================================================
Sort
Reads input, sorts data, and writes the results to the screen, to a file, or to another device.

sort [/r] [/+n] [/m kilobytes] [/l locale] [/rec characters] [[drive1:][path1]filename1] [/t [drive2:][path2]] [/o [drive3:][path3]filename3]

[command |] sort [/r] [/+n] [/m kilobytes] [/l locale] [/rec characters] [[drive1:][path1]filename1] [/t [drive2:][path2]] [/o [drive3:][path3]filename3]

Parameters

/r

Reverses the sort order; that is, sorts from Z to A, and then from 9 to 0.

/+n

Specifies the character position number, n, at which sort begins each comparison. For example, /+3 indicates that each comparison should begin at the third character in each line. Lines with fewer than n characters collate before other lines. By default, comparisons start at the first character in each line.

/m kilobytes

Specifies the amount of main memory to use for the sort, in kilobytes (KB). The memory used is always a minimum of 160 KB. If the memory size is specified, the exact specified amount (but at least 160 KB) is used for the sort, regardless of how much main memory is available.

The default maximum memory size when no size is specified is 90 percent of available main memory if both the input and output are files, and 45 percent of main memory otherwise. The default setting usually gives the best performance.

/l locale

Overrides the sort order of characters defined by the system default locale; that is, the language and Country/Region selected when Windows 2000 was installed. Currently, the only alternative to the default locale is the "C" locale, which is faster than natural language sorting and sorts characters according to their binary encodings.

/rec characters

Specifies the maximum number of characters in a record, or a line of the input file (the default is 4,096, and the maximum is 65,535).

[drive1:][path1]filename1

Specifies the file to be sorted. If no file name is specified, the standard input is sorted. Specifying the input file is faster than redirecting the same file as standard input.

/t [drive2:][path2]

Specifies the path of the directory to hold the sort command's working storage, in case the data does not fit in main memory. The default is to use the system temporary directory.

/o [drive3:][path3]filename3

Specifies the file where the sorted input is to be stored. If not specified, the data is written to the standard output. Specifying the output file is faster than redirecting standard output to the same file.


hth,
B.
Post Reply