This commit is contained in:
2026-03-06 12:33:18 +07:00
parent c2529abe7f
commit 7f0f6ab5ba
115 changed files with 168 additions and 97 deletions
Binary file not shown.
+42 -27
View File
@@ -15,12 +15,19 @@ int main(int argc,char **argv) {
case '2': // Test Sorts case '2': // Test Sorts
{ {
int n; int n;
if(!(argv[1][1]>='a'&&argv[1][1]<='z')) return 0; if(!(argv[1][1]>='a'&&argv[1][1]<='z')){
printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
return 0;}
printf("Write n:"); printf("Write n:");
scanf("%d",&n); scanf("%d",&n);
while(getchar()>'\n'); while(getchar()>'\n');
uint32_t *arr = (uint32_t*)malloc(sizeof(uint32_t) * n); uint32_t *arr = (uint32_t*)malloc(sizeof(uint32_t) * n);
fill_rand(arr, n); printf("Write n nums:");
for (int i = 0;i<n;i++){
scanf("%d",&arr[i]);
}
for(int i = 0; i<n;i++)printf("%d ",arr[i]); for(int i = 0; i<n;i++)printf("%d ",arr[i]);
putchar('\n'); putchar('\n');
@@ -42,17 +49,24 @@ int main(int argc,char **argv) {
for(int i = 0; i<n;i++)printf("%d ",arr[i]); for(int i = 0; i<n;i++)printf("%d ",arr[i]);
break; break;
default: default:
break; printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
return 0;
} }
free(arr);
break; break;
default:
return 0;
} }
case '3': case '3':
{ {
printf("\n N - %d",(18-1)%24+1); printf("\n N - %d",(18-1)%24+1);
break; break;
} }
default:
{
printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
return 0;
}
} }
} }
else{ else{
@@ -71,37 +85,38 @@ void run_exp(void) {
int n = MILLION,end=MILLION,step = 50000; int n = MILLION,end=MILLION,step = 50000;
for (;n<=end;n+=step){ for (;n<=end;n+=step){
uint32_t *arr = (uint32_t*)malloc(sizeof(uint32_t) * n); uint32_t *arrA = (uint32_t*)malloc(sizeof(uint32_t) * n);
uint32_t *arrB = (uint32_t*)malloc(sizeof(uint32_t) * n);
uint32_t *arrC = (uint32_t*)malloc(sizeof(uint32_t) * n);
double tRadTotal = 0; double tRadTotal = 0;
for (int i = 0; i < AVG_TIME_LOOPS; i++) {
fill_rand(arr, n);
double t = get_time();
sort_radix(arr,n);
tRadTotal += (get_time() - t);
}
double tRadRes = tRadTotal / AVG_TIME_LOOPS;
double tHeapTotal = 0; double tHeapTotal = 0;
for (int i = 0; i < AVG_TIME_LOOPS; i++) {
fill_rand(arr, n);
double t = get_time();
sort_heap(arr, n);
tHeapTotal += (get_time() - t);
}
double tHeapRes = tHeapTotal / AVG_TIME_LOOPS;
double tBubblTotal = 0; double tBubblTotal = 0;
for (int i = 0; i < AVG_TIME_LOOPS; i++) { for (int i = 0; i < AVG_TIME_LOOPS; i++) {
fill_rand(arr, n); fill_rand(arrA, n);
double t = get_time(); arrC = arrB = arrA;
sort_bubble(arr,n);
tBubblTotal += (get_time() - t); double ta = get_time();
sort_radix(arrA,n);
tRadTotal += (get_time() - ta);
double tb = get_time();
sort_heap(arrB, n);
tHeapTotal += (get_time() - tb);
double tc = get_time();
sort_bubble(arrC,n);
tBubblTotal += (get_time() - tc);
} }
double tRadRes = tRadTotal / AVG_TIME_LOOPS;
double tHeapRes = tHeapTotal / AVG_TIME_LOOPS;
double tBubblRes = tBubblTotal / AVG_TIME_LOOPS; double tBubblRes = tBubblTotal / AVG_TIME_LOOPS;
free(arrA);
free(arrB);
free(arrC);
fprintf(f, "%d %f %f %f\n", n, tRadRes, tHeapRes, tBubblRes); fprintf(f, "%d %f %f %f\n", n, tRadRes, tHeapRes, tBubblRes);
free(arr);
printf("Sort: %d/%d \r", n, end); printf("Sort: %d/%d \r", n, end);
fflush(stdout); fflush(stdout);
} }
-4
View File
@@ -20,9 +20,5 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR) @mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
run: $(TARGET)
./$(TARGET) < input > output
@cat output
clean: clean:
rm -rf $(OBJ_DIR) $(TARGET) output rm -rf $(OBJ_DIR) $(TARGET) output
Binary file not shown.
Submodule 1Y-2H/gameoflife deleted from feb40df734
Binary file not shown.
Binary file not shown.
Binary file not shown.
-28
View File
@@ -1,28 +0,0 @@
CC = gcc
CFLAGS = -Wall -Wextra -I../ -g
TARGET = matrix
SRC_DIR = ../code
OBJ_DIR = ../.o
SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
.PHONY: all clean run
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(TARGET)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
run: $(TARGET)
./$(TARGET) < input > output
@cat output
clean:
rm -rf $(OBJ_DIR) $(TARGET) output
+44
View File
@@ -0,0 +1,44 @@
[
{
"file": "src/io.c",
"arguments": [
"gcc",
"-I./include",
"-g",
"-c",
"src/io.c",
"-o",
".obj/io.o"
],
"directory": "/home/oniic/Documents/sibsutisiv522s18/1Y-2H/prog",
"output": ".obj/io.o"
},
{
"file": "src/main.c",
"arguments": [
"gcc",
"-I./include",
"-g",
"-c",
"src/main.c",
"-o",
".obj/main.o"
],
"directory": "/home/oniic/Documents/sibsutisiv522s18/1Y-2H/prog",
"output": ".obj/main.o"
},
{
"file": "src/matrix.c",
"arguments": [
"gcc",
"-I./include",
"-g",
"-c",
"src/matrix.c",
"-o",
".obj/matrix.o"
],
"directory": "/home/oniic/Documents/sibsutisiv522s18/1Y-2H/prog",
"output": ".obj/matrix.o"
}
]
Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More