newNode->pre被赋值的时候怎么会警告不兼容呢?
#include <stdio.h>
#include <stdlib.h>
typedef struct node_t
{
int data;
struct note_t* pre;
struct node_t* next;
} Linknote_t;
Linknote_t* createNode(int x)
{
Linknote_t* node = (Linknote_t*)malloc(sizeof(Linknote_t));
if(node == NULL)
{
printf("malloc error\n");
return;
}
node->pre = NULL;
node->next = NULL;
node->data = x;
return node;
}
int lenthList(Linknote_t* p)
{
int count = 0;
Linknote_t* temp = p;
while(temp !=NULL)
{
count++;
temp = temp->next;
}
return count;
}
void insertNodeBack(Linknote_t* p,int pos,int x)//在pos位置后面插入结点
{
if(pos<0||pos>lenthList(p)-1)//pos最大取到链表最后一个结点的位置
{
printf("position error\n");
return;
}
Linknote_t* newNode = (Linknote_t*)malloc(sizeof(Linknote_t));
newNode->data = x;
Linknote_t* temp = p;
int i;
for(i=0;i<pos;i++)
{
temp = temp->next;
}
if(temp->next == NULL)//temp已经是最后一个结点,特殊考虑
{
temp->next = newNode;
newNode->pre = temp; //警告
return;
}
else
{
newNode->next = temp->next;
newNode->pre = temp;//警告
temp->next->pre = newNode;//警告
temp->next = newNode;
}
return;
}
void printLinkList(Linknote_t* p)
{
Linknote_t* temp = p;
while(temp!=NULL)
{
printf("%d->",temp->data);
temp = temp->next;
}
printf("\n");
}
int main()
{
Linknote_t* head = createNode(100);
insertNodeBack(head,0,101);
printf("有效结点数:%d\n",lenthList(head));
printLinkList(head);
return 0;
}