Follow

Translate

Wednesday, March 16, 2016

(QuickSort) This algorithm sorts an array A with N elements.



1.    [Initialize. ] TOP  : = NULL.

2.  [PUSH boundary values of A onto stacks when A has 2 or more elemnts.]
      If N > 1, then  : TOP : =  TOP +1, LOWER[1] : = 1, UPPER[1] : = N.

3.   Repeat Steps 4 to 7 while TOP != NULL.

4.    [Pop sublist from stacks.]

       Set BEG : = LOWER[TOP], End : = UPPER[TOP],
       TOP : = TOP - 1.

5.  Call QUICK(A, N, BEG, END, LOC).

6.     [Push left sublist onto stacks when it has 2 or more elemnts.]

       If BEG < LOC - 1, then:
         TOP : = TOP + 1, LOWER[TOP] : = BEG,
UPPER[TOP] = LOC -1.

[End of If structure.]

7.    [Push right sublist onto stack when it has 2 or more elemnts.]

     If LOC + 1 < End , the:
   TOP : = TOP + 1, LOWER[TOP] : = LOC +1,
         UPPER[TOP] : = END .
 [End of If  structure].
[End of Step 3 loo].

8. Exit.
If You want to learn about the technology, computer science & engineering, web programming, freelancing, earning please click here :CSE SOLVE

0 comments:

Post a Comment