33,028
社区成员
发帖
与我相关
我的任务
分享
struct node{
int key;
node* next;
};
typedef node* List;
List* find(List* head, int k)
{
if (list == NULL || k <= 0)
{
return NULL; //查找失败。
}
List *p = head;
List *tempList = head;
for(int i=0;i<n;i++)
{
templist=templist->next;
if(NULL==templist) //判断如果tempList结点走过尾了,就查找失败。
return NULL;
}
while(tempList->next != NULL)
{
tempList = tempList->next;
p = p->next;
}
return p;
}
}
struct Node{
int key;
node* next;
};
typedef struct Node List; //change point
List* find(List* head, int k)
{
if (NULL==list || k <= 0)
{
return NULL; //查找失败。
}
List *p = head; //这里还用malloc申请内存吗?上面定义List* head,head有头指针,
List *tempList = head;
for(int i=0;i<n;i++)
{
templist=templist->next;
if(NULL==templist) //判断如果tempList结点走过尾了,就查找失败。
return NULL;
}
while(tempList->next != NULL)
{
tempList = tempList->next;
p = p->next;
}
return p;
}
}
typedef struct _Node Node;
typedef struct _Node List;
struct _Node{
void* data;
Node* next;
}
List* list_prepend(List* list,void* data){
Node* node;
node = (Node*)malloc(sizeof(Node));
node->data = data;
node->next = list;
return node;
}