проблема со связанными списками
От: forston  
Дата: 08.06.09 08:02
Оценка:
struct node {
    HINTERNET hInternetConnect; // handle from InternetConnect
    HINTERNET hOpenRequest;
    struct node *next;
};

struct node *n = NULL;

struct node **list_search(struct node **n, HINTERNET hInternetConnect) {
    while (*n != NULL) {
        if ((*n)->hInternetConnect == hInternetConnect) {
            return n;
        }
        n = &(*n)->next;
    }
    return NULL;
}

struct node *list_add(struct node **p, HINTERNET hInternetConnect) {
    if (list_search(&(*p), hInternetConnect) == NULL) {
        struct node *n = (node*)malloc(sizeof(struct node));
        if (n == NULL)
            return NULL;
     
        n->next = *p;
        *p = n;
        n->hInternetConnect = hInternetConnect;
     
        return *p;
    }
}
 
void list_remove(struct node **p) {
    if (*p != NULL) {
        struct node *n = *p;
        *p = (*p)->next;
        free(n);
    }
}

void list_update(struct node **p, LPCTSTR hOpenRequest) {
    if (*p != NULL) {
        (*p)->hOpenRequest= hOpenRequest;
    }
}


при добавлении все работает
list_add(&n, hInternet);
поиск отдельно тоже работает — list_search(&n, hConnect)

но если сделать удаление, то все крашится.
list_remove(list_search(&n, hConnect));

никак не могу понять в чем причина.. вроде все верно :(
linked lists
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.