forked from personal/squiggle.c
run formatter in quickselect
This commit is contained in:
parent
03ca3e3b0c
commit
dc3f7eed4d
|
@ -3,3 +3,9 @@ build:
|
||||||
|
|
||||||
run:
|
run:
|
||||||
./quickselect
|
./quickselect
|
||||||
|
|
||||||
|
## Formatter
|
||||||
|
STYLE_BLUEPRINT=webkit
|
||||||
|
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
||||||
|
format:
|
||||||
|
$(FORMATTER) quickselect.c
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void swp(int i, int j, double xs[]){
|
void swp(int i, int j, double xs[])
|
||||||
|
{
|
||||||
double tmp = xs[i];
|
double tmp = xs[i];
|
||||||
xs[i] = xs[j];
|
xs[i] = xs[j];
|
||||||
xs[j] = tmp;
|
xs[j] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void array_print(double xs[], int n){
|
void array_print(double xs[], int n)
|
||||||
|
{
|
||||||
printf("[");
|
printf("[");
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
printf("%f, ", xs[i]);
|
printf("%f, ", xs[i]);
|
||||||
|
@ -16,7 +18,8 @@ void array_print(double xs[], int n){
|
||||||
printf("]\n");
|
printf("]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int partition(int low, int high, double xs[], int length){
|
int partition(int low, int high, double xs[], int length)
|
||||||
|
{
|
||||||
// To understand this function:
|
// To understand this function:
|
||||||
// - see the note after gt variable definition
|
// - see the note after gt variable definition
|
||||||
// - go to commit 578bfa27 and the scratchpad/ folder in it, which has printfs sprinkled throughout
|
// - go to commit 578bfa27 and the scratchpad/ folder in it, which has printfs sprinkled throughout
|
||||||
|
@ -34,7 +37,8 @@ int partition(int low, int high, double xs[], int length){
|
||||||
return gt;
|
return gt;
|
||||||
}
|
}
|
||||||
|
|
||||||
double quickselect(int k, double xs[], int length){
|
double quickselect(int k, double xs[], int length)
|
||||||
|
{
|
||||||
int low = 0;
|
int low = 0;
|
||||||
int high = length - 1;
|
int high = length - 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -52,7 +56,8 @@ double quickselect(int k, double xs[], int length){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main()
|
||||||
|
{
|
||||||
double xs[] = { 2.1, 1.0, 6.0, 4.0, 7.0, -1.0, 2.0, 10.0 };
|
double xs[] = { 2.1, 1.0, 6.0, 4.0, 7.0, -1.0, 2.0, 10.0 };
|
||||||
int length = 8;
|
int length = 8;
|
||||||
int k = 2;
|
int k = 2;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user