想要简单的实现以下链表,然后这次尝试在函数内完成head的建立,结果因为同级指针的问题,不能修改主函数的head,请把这段完善
#include <stdio.h>
#include <stdlib.h>
typedef struct NODE{
int date;
struct Node *next;
}Node;
Node* create(int a){
Node *node = (Node*)malloc(sizeof (Node));
node->date = a;
node->next = NULL;
return node;
}
void insert(Node* head){
int a;
scanf("%d",&a);
Node* new = create(a);
if(head==NULL){
Node **head = &head;
*head = new;
} else{
Node* p = head;
while (p->next){
p=p->next;
}
p->next = new;
}
}
void print(Node*head)
{
Node* pMove=head;
while(pMove)
{
printf("%d ",pMove->date);
pMove=pMove->next;
}
}
void delete(Node*head,int count){
Node* pMove=head;
for(int i=0;i<count-1;i++){
pMove = pMove->next;
}
if(pMove+2!=NULL){
pMove->next = (pMove+2);
} else{
pMove->next=NULL;
}
}
int main() {
Node *head = NULL;
for(int i = 0 ; i<=1;i++){
insert(head);
}
print(head);
}
请求修改位置:
insert函数下:
if(head==NULL){
Node **head = &head;
*head = new;
}
为了方便验证,主函数就只用了输入两次.