Skip to content
Snippets Groups Projects
Commit 2342f229 authored by thibault.chatillo's avatar thibault.chatillo
Browse files

matrix2tree

parent 02c41437
No related branches found
No related tags found
No related merge requests found
cc=gcc
CFLAGS=-Wextra -Wall -g -fsanitize=address -fsanitize=leak
LFLAGS=-fsanitize=address -fsanitize=leak -lm
CFLAGS=-Wextra -Wall -g -fsanitize=address
LFLAGS=-fsanitize=address -lm
# -fsanitize=leak mac
main: main.x
./main.x
......
......@@ -19,7 +19,7 @@ pgm_error pmg_read_from_file(pgm *p, char *filename) {
FILE *f = fopen(filename, "r");
if (f == NULL) {
printf("error with file");
printf("error with file read");
return failure;
}
......@@ -58,7 +58,7 @@ pgm_error pmg_write_to_file(pgm *p, char *filename) {
FILE *f = fopen(folder, "w");
if (f == NULL) {
printf("error with file");
printf("error with file write");
return failure;
}
fprintf(f, "%s\n%d %d\n%d\n", "P5", p->pixels.m, p->pixels.n, p->max);
......
This diff is collapsed.
File added
......@@ -4,11 +4,21 @@
int main() {
pgm p;
pmg_read_from_file(&p, "chien-pasteque.pgm");
create_tree(3);
pmg_read_from_file(&p, "buzz_octets.pgm");
node* tree=create_tree(2);
while (!leaf(tree->child[0]))
{
printf("not leaf\n");
/* code */
tree=tree->child[0];
}
// printf("%f val %d\n",tree->child[0]->child[0]->ave,depth(tree)-1);
// position(3,3,trkee,4);
// matrix2tree(&p.pixels,tree);
// destroy_tree(tree);
// pmg_write_to_file(&p,"buzz.pgm");
matrix_destroy(&p.pixels);
// matrix_destroy(&p.pixels);
}
\ No newline at end of file
......@@ -12,8 +12,10 @@ bool leaf(node *nd) { return NULL == nd->child[0]; }
node *create_node() {
node *nd = malloc(sizeof(node));
for (int i = 0; i < CHILDREN; i++) {
nd->child[i] = calloc(1, sizeof(node));
// if(nd->child[i]!=NULL)printf("wtf");
}
nd->ave = 0;
nd->ave_sq = 0;
......@@ -60,11 +62,40 @@ void symetry(node *arbre, int bit) {
}
node *position(int li, int col, node *a, int d) {
if(leaf(a)){
printf("is leaf %d\n",d);
return a;
}
printf("not leaf %d\n",d);
node *crt = a;
// à compléter: tant qu’on n’est pas sur une feuille, déplacer
// <crt> sur un enfant selon valeur du d­ième bit de <li> et <col>
int size=pow(2,d);
int half=size/2;
int i;
if(li<half&&col<half){
i=0;
}else if(li<half&&col>half)
{
i=1;
}
else if(li>half&&col<half)
{
i=2;
}
else if(li>half&&col>half)
{
i=3;
}
// printf("%d \n\n\n",i);
crt=crt->child[i];
crt=position(li%2,col%2,crt,d-1);
return crt;
}
// à compléter: tant qu’on n’est pas sur une feuille, déplacer
// <crt> sur un enfant selon valeur du dième bit de <li> et <col>
void matrix2tree(matrix *mat, node *arbre) {
int d = depth(arbre) - 1;
......
......@@ -3,7 +3,8 @@
#include <stdio.h>
#include <stdbool.h>
#include <malloc.h>
#include <stdlib.h>
// #include <malloc.h>
#include "matrix.h"
#include <string.h>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment