Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Quicksort taking random pivot

partition(arr[], lo, hi) 
    pivot = arr[hi]
    i = lo     // place for swapping
    for j := lo to hi – 1 do
        if arr[j] <= pivot then
            swap arr[i] with arr[j]
            i = i + 1
    swap arr[i] with arr[hi]
    return i

partition_r(arr[], lo, hi)
    r = Random Number from lo to hi
    Swap arr[r] and arr[hi]
    return partition(arr, lo, hi)

quicksort(arr[], lo, hi)
    if lo < hi
        p = partition_r(arr, lo, hi)
        quicksort(arr, lo , p-1)
        quicksort(arr, p+1, hi)
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to get the type of a variable in c++ 
Cpp :: calloc c++ 
Cpp :: continue c++ 
Cpp :: std distance 
Cpp :: how to split a string in c++ 
Cpp :: c++ Sum of all the factors of a number 
Cpp :: how to delete a file in cpp 
Cpp :: string to uint64_t c++ 
Cpp :: c++ cout format 
Cpp :: int max c++ 
Cpp :: cpp get last element of vector 
Cpp :: sort vector struct c++ 
Cpp :: c++ remove element from vector 
Cpp :: draw rectangle opencv c++ 
Cpp :: comparator in sort c++ 
Cpp :: cpp absolute value 
Cpp :: chudnovsky algorithm c++ 
Cpp :: string vector to string c++ 
Cpp :: remove element from vector c++ 
Cpp :: c++ capture screen as pixel array 
Cpp :: how many months have 31 days 
Cpp :: c++ if example 
Cpp :: after login redirect to dashboard in nuxt 
Cpp :: joining two vectors in c++ 
Cpp :: find a number in vector c++ 
Cpp :: cpp template 
Cpp :: c++ initialise array 
Cpp :: exception handling class c++ 
Cpp :: c++ check if key exists in map 
Cpp :: prevent copy c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =