struct no { int v; struct no *prox; }; struct no *novo(int v, struct no *prox) { struct no *n = malloc(sizeof(struct no)); n-> v = v; n-> prox = prox; return n; } struct no *copia_rec(struct no *n) { if (n == NULL) return NULL; return novo(n->v, copia_rec(n->prox)); } struct no *copia_for(struct no *n) { struct no *copia, *c0; if (n == NULL) return NULL; copia = c0 = novo(n->v, NULL); for (n = n->prox; n != NULL; n = n->prox) { copia->prox = novo(n->v, NULL); copia = copia->prox; } return c0; }
struct no *rev_copia(struct no *n) { struct no *rev = NULL; for (; n != NULL; n = n->prox) { rev = novo(n->v, rev); } return rev; }
void rec_rev(struct no *n, struct no *prev) { if (n == NULL) return; rec_rev(n->prox, n); n->prox = prev; }
char *copia_str(char *str) { char *copia = malloc(sizeof(char)*strlen(str)); strcpy(copia, str); return copia; }
void insere(struct no *ant, int v) { ant->prox = novo(v, ant->prox); } void remove(struct no *ant) { struct no *r = ant->prox; ant->prox = r->prox; free(r); }
Date: 2010-11-16 15:24:41 BRST
HTML generated by org-mode 6.21b in emacs 23