I C에 연결 목록에서 일반 데이터를 제거하려면 다음 기능이 있습니다C 무효 포인터와 포인터 비교
void removeData(void *data, struct accList *theList)
{
struct accListNode* cur = theList->head;
struct accListNode* prev = NULL;
for(; cur != NULL; prev = cur, cur = cur->next)
{
if(cur->data == data)
{
if(cur == theList->head)
{
theList->head = cur->next;
}
if(cur == theList->tail)
{
theList->tail = prev;
}
if(prev != NULL)
{
prev->next = cur->next;
}
free(cur);
return;
}
}
}
cur->data == data
뒤에있는 의미는 무엇입니까?
내 데이터는 일반 (void*
)이므로 모든 기본 유형 및 구조 유형에 대해 이것이 무엇을 의미합니까?
예를 들어, 직원의 구조를 고려 :
struct employee
{
char name[20];
float wageRate;
};
어떻게 것 문 cur->data == data
작업 데이터 유형 struct employee*
인 경우? 데이터는 구조체의 첫 번째 메모리 주소에 대한 포인터이므로 포인터 주소를 비교하고 있습니까?
포인터 주소 (예 :'& data')를 비교하지 않고 주소 인 포인터를 비교하고 있습니다. – sczizzo