void createnode(int n)
{
int data ;
struct node *temp;
/* lets create first node using malloc */
head=(struct node*)malloc(sizeof(struct node));
if(head == NULL)
{
printf("Memory not allocated ");
return;
}
printf("Enter first node data ");
scanf("%d", &data);
temp=head;
head-> data = data;
head->link=NULL;
for(int i=2; i<=n; i++)
{
struct node *NewNode=(struct node *)malloc(sizeof(struct node));
if(NewNode== NULL)
{
printf("Memory not allocated ");
break;
}
printf("Enter node data ");
scanf("%d", &data);
NewNode->data=data;
NewNode->link=NULL;
temp->link=NewNode; // linking current node with NewNode
temp = temp->link; // Moving temp node to NewNode location
}
printf("List created successfuly!\n");
}
{
int data ;
struct node *temp;
/* lets create first node using malloc */
head=(struct node*)malloc(sizeof(struct node));
if(head == NULL)
{
printf("Memory not allocated ");
return;
}
printf("Enter first node data ");
scanf("%d", &data);
temp=head;
head-> data = data;
head->link=NULL;
for(int i=2; i<=n; i++)
{
struct node *NewNode=(struct node *)malloc(sizeof(struct node));
if(NewNode== NULL)
{
printf("Memory not allocated ");
break;
}
printf("Enter node data ");
scanf("%d", &data);
NewNode->data=data;
NewNode->link=NULL;
temp->link=NewNode; // linking current node with NewNode
temp = temp->link; // Moving temp node to NewNode location
}
printf("List created successfuly!\n");
}
No comments:
Post a Comment