Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Write an algorithm for Quick Sort in dfs (data file structure).

  Shared By: Ballard Schmidt    Date: Nov 03    Category: C++ Programming    Views: 1865

Answer:

1. [Initialization]
g <-- lb + 1
s <-- ub
flag <-- 0
key <-- sortarray [lb]
temp.

2. [Check we have single element array or not]
if lb < ub
[Repeat until key value is position at its final position]
while flag =0

[Position g no greater than key]
Repeat while sortarray [g] < key
Increment g by 1.

Repeat while sortarray [s] > key
Decrement s by 1.

[Check whether s is pointing to lower position]
if g < s
[Exchange values of g and s]
else
flag = 1
[Exchange the s with key position]

Call quicksort (sortarray,lb,s-1)
Call quicksort (sortarray,s+1,ub)

Share: 
 


Related Topics:

Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: