This commit is contained in:
Damián Korpesio 2022-01-20 08:04:32 +01:00
parent 6a26a4026d
commit 4c1881da8c
5 changed files with 9 additions and 24 deletions

BIN
sk1a.zip

Binary file not shown.

View File

@ -4,19 +4,19 @@
#include <assert.h> #include <assert.h>
int issafe(char* maze, int x, int y, int size) { int issafe(char* maze, int x, int y, int size) {
if ((x >= 0 && x < size) && (y >= 0 && y < size) && (maze[x * size + y] == ' ')){ if ((x >= 0 && x < size) && (y >= 0 && y < size) && (maze[x * size + y] == ' ')){
return 1; return 1;
} }
return 0; return 0;
} }
int backtracking(char* maze, int x, int y, int size){ int backtracking(char* maze, int x, int y, int size){ //https://www.geeksforgeeks.org/rat-in-a-maze-backtracking-2/
if(x == size - 1 && y == size - 1 && maze[x * size + y] == ' '){ if(x == size - 1 && y == size - 1 && maze[x * size + y] == ' '){ //kontrola ci sa nachadzam na konci
maze[x * size + y] = '*'; maze[x * size + y] = '*';
return 1; return 1;
} }
if(issafe(maze, x, y, size) == 1) { if(issafe(maze, x, y, size) == 1) { // znazornenie stien
maze[x * size + y] = '*'; maze[x * size + y] = '*';
if (backtracking(maze, x, y + 1, size) == 1) { if (backtracking(maze, x, y + 1, size) == 1) {

View File

@ -24,7 +24,7 @@ void delete(struct dict* tree){
for (int i = 0 ;i < SIZE; i++){ for (int i = 0 ;i < SIZE; i++){
delete(tree-> characters[i]); delete(tree-> characters[i]);
} }
free(tree);
} }
void get_words (struct dict* tree,char* words[]){ void get_words (struct dict* tree,char* words[]){
@ -102,7 +102,7 @@ int mylz78compress(char* buff,int size,char** outbuf){
} }
delete(root); delete(root);
free(words);
*outbuf = temp; *outbuf = temp;
return strlen(temp); return strlen(temp);
@ -183,9 +183,7 @@ void compress(FILE* infile,FILE* outfile){
fwrite(outbuf,sizeof(char),outsize,outfile); fwrite(outbuf,sizeof(char),outsize,outfile);
} }
free(buffer);
free(tempbuf);
free(outbuf);
} }
@ -204,7 +202,6 @@ int myrldecompress(char* buff,int size,char** outbuf){
char *tempbuf = calloc(size,sizeof(char)); char *tempbuf = calloc(size,sizeof(char));
memset(tempbuf,'\0',size); memset(tempbuf,'\0',size);
strcpy(tempbuf,*outbuf); strcpy(tempbuf,*outbuf);
free(*outbuf);
*outbuf = tempbuf; *outbuf = tempbuf;
} }
@ -242,7 +239,6 @@ int mylz78decompress(char* buff,int size,char** outbuf){
char *tempbuf = calloc(size,sizeof(char)); char *tempbuf = calloc(size,sizeof(char));
memset(tempbuf,'\0',size); memset(tempbuf,'\0',size);
strcpy(tempbuf,*outbuf); strcpy(tempbuf,*outbuf);
free(*outbuf);
*outbuf = tempbuf; *outbuf = tempbuf;
} }
@ -278,8 +274,5 @@ void decompress(FILE* infile,FILE* outfile){
fwrite(outbuf,sizeof(char),outsize,outfile); fwrite(outbuf,sizeof(char),outsize,outfile);
} }
free(buffer);
free(tempbuf);
free(outbuf);
} }

Binary file not shown.

View File

@ -24,7 +24,6 @@ return;
for (int i = 0 ;i < SIZE; i++){ for (int i = 0 ;i < SIZE; i++){
delete(tree-> characters[i]); delete(tree-> characters[i]);
} }
free(tree);
} }
void get_words (struct dict* tree,char* words[]){ //posielam cely strom a smernik na dvojrozmerne pole void get_words (struct dict* tree,char* words[]){ //posielam cely strom a smernik na dvojrozmerne pole
@ -102,7 +101,7 @@ sprintf(last,"-%d-%c\n",current->index,c); //
} }
delete(root); //nepotrebujeme strom, uvolnime pamat delete(root); //nepotrebujeme strom, uvolnime pamat
free(words);
*outbuf = temp; //adresa sa zapise do outbuffer *outbuf = temp; //adresa sa zapise do outbuffer
return strlen(temp); return strlen(temp);
@ -183,9 +182,7 @@ char *buffer = calloc(insize,sizeof(char)); //alokuje pamat
fwrite(outbuf,sizeof(char),outsize,outfile); //napise sa do suboru, z akeho buffera do akeho suboru fwrite(outbuf,sizeof(char),outsize,outfile); //napise sa do suboru, z akeho buffera do akeho suboru
} }
free(buffer);
free(tempbuf);
free(outbuf);
} }
@ -204,7 +201,6 @@ memset(*outbuf,0,size + 1);
char *tempbuf = calloc(size,sizeof(char)); char *tempbuf = calloc(size,sizeof(char));
memset(tempbuf,'\0',size); memset(tempbuf,'\0',size);
strcpy(tempbuf,*outbuf); strcpy(tempbuf,*outbuf);
free(*outbuf);
*outbuf = tempbuf; *outbuf = tempbuf;
} }
@ -242,7 +238,6 @@ int bytes_read, bytes_read_all = 0; //citame vstupny buffer, necitame p
char *tempbuf = calloc(size,sizeof(char)); char *tempbuf = calloc(size,sizeof(char));
memset(tempbuf,'\0',size); memset(tempbuf,'\0',size);
strcpy(tempbuf,*outbuf); strcpy(tempbuf,*outbuf);
free(*outbuf);
*outbuf = tempbuf; *outbuf = tempbuf;
} }
@ -278,7 +273,4 @@ char *buffer = calloc(insize,sizeof(char));
fwrite(outbuf,sizeof(char),outsize,outfile); fwrite(outbuf,sizeof(char),outsize,outfile);
} }
free(buffer);
free(tempbuf);
free(outbuf);
} }