Fixed some memory errors
This commit is contained in:
parent
abff9057b5
commit
f26825e77b
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
a.out
|
a.out
|
||||||
main
|
main
|
||||||
.vscode
|
.vscode
|
||||||
|
vgcore*
|
24
main.c
24
main.c
@ -117,6 +117,12 @@ arr *reverse(arr *a)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_arr(arr *a)
|
||||||
|
{
|
||||||
|
free(a->p);
|
||||||
|
free(a);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Business logic
|
Business logic
|
||||||
*/
|
*/
|
||||||
@ -200,7 +206,7 @@ arr *compose_interpolation_polynomial(arr *xes, arr *ys)
|
|||||||
{
|
{
|
||||||
arr *res = init(xes->size);
|
arr *res = init(xes->size);
|
||||||
|
|
||||||
arr *jcoef = init(xes->size - 1);
|
arr *jcoef = init(xes->size);
|
||||||
for (int j = 0; j < xes->size; j++)
|
for (int j = 0; j < xes->size; j++)
|
||||||
{
|
{
|
||||||
int minus = !(xes->size % 2);
|
int minus = !(xes->size % 2);
|
||||||
@ -217,9 +223,11 @@ arr *compose_interpolation_polynomial(arr *xes, arr *ys)
|
|||||||
}
|
}
|
||||||
|
|
||||||
res = add(res, jcoef);
|
res = add(res, jcoef);
|
||||||
|
|
||||||
|
free_arr(xis);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(jcoef);
|
free_arr(jcoef);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -237,8 +245,8 @@ int main()
|
|||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
int x, y;
|
float x, y;
|
||||||
scanf("%d %d", &x, &y);
|
scanf("%f %f", &x, &y);
|
||||||
|
|
||||||
insert(xes, i, x);
|
insert(xes, i, x);
|
||||||
insert(ys, i, y);
|
insert(ys, i, y);
|
||||||
@ -251,7 +259,13 @@ int main()
|
|||||||
arr *res = compose_interpolation_polynomial(xes, ys);
|
arr *res = compose_interpolation_polynomial(xes, ys);
|
||||||
|
|
||||||
printf("Resulting polynomial will have such coeficients:\n");
|
printf("Resulting polynomial will have such coeficients:\n");
|
||||||
printa(reverse(res));
|
arr *reversed = reverse(res);
|
||||||
|
printa(reversed);
|
||||||
|
|
||||||
|
free_arr(reversed);
|
||||||
|
free_arr(res);
|
||||||
|
free_arr(xes);
|
||||||
|
free_arr(ys);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user