1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node {
char *data;
int i;
struct node *next;
};
static struct node *new(char *elt) {
struct node *n = (struct node *) malloc(sizeof(struct node));
n->data = elt;
n->i = 0;
n->next = NULL;
return n;
}
static void print(struct node *n) {
fprintf(stdout, "%p %s\n", n->next, n->data);
}
static struct node *append(struct node *n, char *elt) {
for(; n->next != NULL; n = n->next);
n->next = new(elt);
return n;
}
int main(void) {
int i = 0;
struct node *n = new(NULL);
while(i++ < 100000) {
print(append(n, "sring"));
}
return 0;
} |
Partager