Skip to content
Snippets Groups Projects
Commit 75f8ba38 authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

ADD: ex3, now everything works

parent 40b9a402
No related branches found
No related tags found
No related merge requests found
......@@ -34,50 +34,6 @@ void list_push(list* ll, const int v) {
ll->head = e;
}
void list_insert(list* ll, const int n, const int v) {
if (n < 0) { return; }
elem *e = malloc(sizeof(elem));
e->value = v;
e->next = NULL;
if (0 == n) {
e->next = ll->head;
ll->head = e;
} else {
int count = 1;
elem *prev = ll->head;
while (count < n) {
if (NULL == prev->next) { return; }
prev = prev->next;
++count;
}
elem *follow = prev->next;
e->next = follow;
prev->next = e;
}
}
void list_remove(list *ll, const int n) {
if (n < 0) { return; }
if (0 == n) {
elem *e = ll->head;
ll->head = ll->head->next;
free(e);
} else {
int count = 1;
elem *prev = ll->head;
elem *e = prev->next;
while (count < n) {
if (NULL == e) { return; }
prev = e;
e = e->next;
++count;
}
if (e != NULL) { prev->next = e->next; }
else { prev->next = NULL; }
free(e);
}
}
void list_print(const list *ll) {
elem *e = ll->head;
while (e != NULL) {
......@@ -94,19 +50,29 @@ void list_print(const list *ll) {
list pascal(const int line) {
if (line <= 1) {
list ll = list_create();
ll.push(1);
list_push(&ll, 1);
return ll;
} else {
list above = pascal(line-1); // rec
elem *e = above.head;
list_ll = list_create();
list_destroy(&above);
list prevline = pascal(line-1); // rec
// 2l: on "triche" et on utilise la symmétrie du triangle
list ll = list_create();
list_push(&ll, 1);
elem *above = prevline.head;
elem *northwest = prevline.head->next;
while (northwest != NULL) {
// même trick
list_push(&ll, above->value + northwest->value);
above = northwest;
northwest = northwest->next;
}
list_push(&ll, 1);
list_destroy(&prevline);
return ll;
}
}
int main(int argc, char **argv) {
int main() {
int line;
scanf("%d", &line);
printf("\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment