- Codice:
struct list {
float value;
struct list *next_ptr;
};
void suf_insert(struct list **ptrptr, float v) {
while (*ptrptr != NULL) {
ptrptr = &((*ptrptr)->next_ptr);
}
pre_insert(ptrptr, v);
}
Grazie
struct list {
float value;
struct list *next_ptr;
};
void suf_insert(struct list **ptrptr, float v) {
while (*ptrptr != NULL) {
ptrptr = &((*ptrptr)->next_ptr);
}
pre_insert(ptrptr, v);
}
struct list_node {
float value;
struct list *next;
};
struct list {
struct list_node ROOT;
};
void list_init(struct list *lst) {
lst->ROOT->next = &(lst->ROOT);
}
/* Ogni lista ha almeno un nodo per cui non c'è alcun caso particolare */
void list_insert(struct list_node *n, float v) {
struct list_node *new_node = malloc(sizeof(struct list_node));
new_node->value = v;
new_node->next = n->next;
n->next = new_node;
}
void pre_insert(struct list *lst, float v) {
return list_insert(lst->ROOT, v);
}
struct list_node *find_last(struct list *lst) {
struct list_node *current = lst->ROOT;
while (current->next != lst->ROOT) { current = current->next; }
return current;
}
void suf_insert(struct list *lst, float v) {
list_insert(find_last(lst), v);
}
void ord_insert(struct list **ptrptr, float v) {
while (*ptrptr != NULL && ((*ptrptr)->value<v)) {
ptrptr = &((*ptrptr)->next_ptr);
}
pre_insert(ptrptr, v);
}
Visitano il forum: Nessuno e 1 ospite