Code:
void InsertInFront(NodePointer Head, int Num)
{
NodePointer NewNode;
NewNode=(NodePointer)malloc(sizeof(struct Node));
NewNode->Data=Num;
NewNode->Link=Head;
Head=NewNode;
}
There is a problem with your insert function. At the end you set Head equal to the new node, but this change does not affect the Head declared in main at all.
Change the function to return a NodePointer, and do "return (NewNode);"
The call would then look like this
Head = InsertInFront(Head,number);
Code:
int DeleteFront(NodePointer Head)
{
NodePointer Temp;
int num;
if(Head==NULL) {
printf("The list is empty.Cannot delete.");
return ;
}
while(Head->Link!=NULL)
{
Temp=Head;
printf ( "%d\n", Temp->Data);
Head=Head->Link;
free(Temp);
}
return ;
}
This function is a bit buggy, instead of deleteing the front element, you iterate through the list freeing all the nodes, except for the last one. Try this function.
Code:
NodePointer DeleteFront(NodePointer Head)
{
NodePointer Temp;
int num;
if(Head==NULL) {
printf("The list is empty.Cannot delete.");
return NULL; /*return the same empty list we recieved */
}
Temp = Head->Link; /* This will become the new head */
free(Head); /*Free the memory */
return Temp; /*Return the new head of the list */
}
This would also be called like this
Head = DeleteFront(Head);