Let A be a list of n numbers .Sorting A refers to the operation of rearranging the elements of A so they are in increasing order .i.e .. so that ...
A[1] < A[2] < A[3] < ..... < A[N]
For example , suppose A is is originally in the list ..
8,4,19,2,7,13,5,16
After sorting ..
2,4,5,7,8,13,16,19
BUBBLE(DATA,N)
Here DATA is an array with N elements .This algorithm sorts the elements in DATA.
1.Repeat Steps 2 and 3 for i=1 to N-1.
2. set PTR = 1 [initialize pass pointer PTR ]
3. Repeat while PTR <= i - j [Executes pass ]
(a) If DATA[PTR]>DATA[PTR + 1] ,then
Interchange DATA[PTR] and DATA[PTR + 1]
[End of if structure ]
(b) Set PTR = PTR + 1
[End of inner loop ]
[End of step 1 outer loop]
4. EXIT
A[1] < A[2] < A[3] < ..... < A[N]
For example , suppose A is is originally in the list ..
8,4,19,2,7,13,5,16
After sorting ..
2,4,5,7,8,13,16,19
BUBBLE(DATA,N)
Here DATA is an array with N elements .This algorithm sorts the elements in DATA.
1.Repeat Steps 2 and 3 for i=1 to N-1.
2. set PTR = 1 [initialize pass pointer PTR ]
3. Repeat while PTR <= i - j [Executes pass ]
(a) If DATA[PTR]>DATA[PTR + 1] ,then
Interchange DATA[PTR] and DATA[PTR + 1]
[End of if structure ]
(b) Set PTR = PTR + 1
[End of inner loop ]
[End of step 1 outer loop]
4. EXIT
No comments:
Post a Comment