リンクリストの開始時にノードを追加しようとしていますが、コード内に最後の要素しか表示されません。なぜこれが問題なのですか?表示機能リンクリストコードが機能しない
#include <stdio.h>
//node structure
struct node
{
int data;
struct node *next;
};
//構造体
//datatype declaration
typedef struct node node ;
// head pointer which will indicate starting point of link list
node *head;
//create fuction that will insert values into note and its next pointer field
void create(int num);
//display function will display the link list
void display();
main()
{
int num,i,n;
printf("enter the nno of node to create : ");
scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("enter data for node %d= ",i+1);
scanf("%d",&num);
create(num);
}
display();
//表示コール
}
void create(int num)
{
head=NULL;
node *temp;
temp=(node*)malloc(sizeof(node));
temp->data=num;
temp->next=head;
head=temp;
return;
}
//関数()終了
void display()
{
node *temp1;
temp1=head;
while(temp1!=NULL)
{
printf("data : %d-> ",temp1->data);
temp1=temp1->next;
}
return;
}
// fucntion表示を()を作成