dsalglib
1.0.0
dsalglib is a ready to use data structures and algorithms library written in C++ . Object Oriented Template implementations are written.
Main Page
Namespaces
Classes
Files
File List
File Members
source
include
quicksort.h
Go to the documentation of this file.
1
//
2
// Created by moghya_s on 12/26/2016.
3
//
4
5
#ifndef DSALGLIB_QUICKSORT_H_H
6
#define DSALGLIB_QUICKSORT_H_H
7
8
#include "
array.h
"
9
10
namespace
dsa
11
{
12
template
<
typename
type>
13
long
long
int
partition
(
array<type>
arr,
long
long
int
start,
long
long
int
end)
14
{
15
type var = arr[end];
16
long
long
int
i,j;
17
i=start-1;
18
for
(j=start;j<end;j++)
19
{
20
if
(arr[j]<=var)
21
{ i++;
22
swapit
(arr[i],arr[j]);
23
}
24
}
25
i++;
26
swapit
(arr[i],arr[end]);
27
return
i;
28
}
29
30
template
<
typename
type>
31
void
quicksort
(
array<type>
arr,
long
long
int
start,
long
long
int
end)
32
{
33
if
(start<end)
34
{
35
long
long
int
pivot;
36
pivot =
partition
(arr,start,end);
37
quicksort
(arr,start,pivot-1);
38
quicksort
(arr,pivot+1,end);
39
}
40
}
41
42
}
43
#endif //DSALGLIB_QUICKSORT_H_H
dsa::swapit
void swapit(T &x, T &y)
Definition:
alginc.h:17
dsa::quicksort
void quicksort(array< type > arr, long long int start, long long int end)
Definition:
quicksort.h:31
dsa
Definition:
alginc.h:12
array.h
dsa::array
Definition:
array.h:10
dsa::partition
long long int partition(array< type > arr, long long int start, long long int end)
Definition:
quicksort.h:13
Generated by
1.8.11