Last active
December 15, 2015 07:29
-
-
Save kyuden/5223812 to your computer and use it in GitHub Desktop.
何らかのCプログラムをコンパイルするRakefileが書けるようになった
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void QuickSort(int x[], int left, int right); | |
void ShowData(int x[], int count); | |
int main(void) | |
{ | |
int array[10] = {4, 7, 0, 9, 8, 1, 6, 2, 3, 5}; | |
int arraySize = sizeof(array) / sizeof(array[0]); | |
QuickSort(array, 0, arraySize-1); | |
ShowData(array, arraySize); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void QuickSort(int x[], int left, int right) | |
{ | |
int le, ri; | |
int midVal; | |
int buf; | |
le = left; | |
ri = right; | |
midVal = x[(left + right) / 2]; | |
while(1) | |
{ | |
while(x[le] < midVal) le++; | |
while(x[ri] > midVal) ri--; | |
if (le >= ri) break; | |
buf = x[le]; | |
x[le] = x[ri]; | |
x[ri] = buf; | |
le++; | |
ri--; | |
} | |
ShowData(x, right); | |
if(left < le-1) QuickSort(x, left, le-1); | |
if(ri+1 < right ) QuickSort(x, ri+1, right); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = "gcc" | |
task :default => "./quicksort" | |
desc "Execute quicksort in console" | |
task "execute_quicksort" => ["quicksort"] do |t| | |
sh "./quicksort" | |
end | |
desc "Link .o Source files" | |
file "quicksort" => ["showdata.o", "quicksort_sub.o", "quicksort.o"] do |t| | |
sh "#{CC} -o #{t.name} #{t.prerequisites.join(' ')}" | |
end | |
desc "Compile .c Source files" | |
rule '.o' => '.c' do |t| | |
sh "#{CC} -c #{t.source}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void ShowData(int x[], int count) | |
{ | |
int i; | |
for(i = 0; i < count; i++) | |
printf("%d", x[i]); | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment