Page 108 - DCAP407_DATA_STRUCTURE
P. 108
Unit 6: Linked List Operations
else
{
return(1);
}
}
void insert_beg(int num)
{
newnode=(struct list*)malloc(sizeof(struct list));
newnode->value=num;
if(HEAD==NULL)
{
HEAD=newnode;
newnode->next=NULL;
}
else
{
newnode->next=HEAD;
HEAD=newnode;
}
}
Output:
When you run the program, the following output is obtained:
Menu
1. Create node
2. Display
3. Insert node at the beginning
4. Exit
Enter your choice:
1
Enter data: 40
Do you want to create another node(y/n)
y
Enter data: 50
Do you want to create another node(y/n)
n
LOVELY PROFESSIONAL UNIVERSITY 101