Skip to content

Instantly share code, notes, and snippets.

@AakashCode12
Created August 14, 2020 16:18
Show Gist options
  • Save AakashCode12/6fe9c97e392793cf7f156bd5ae84c45f to your computer and use it in GitHub Desktop.
Save AakashCode12/6fe9c97e392793cf7f156bd5ae84c45f to your computer and use it in GitHub Desktop.
void insertBefore()
{
int flagforerrormsg = 0;
if (flagforstart == 0)
{
printf("\nThe Linked List is Empty. Add Elements to the Linked List use this function\n");
}
else
{
printf("\nEnter the data Before which you want to add the Node : ");
int num;
scanf("%d", &num);
temp = backtemp = head;
while (1)
{
if (temp->data == num)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf("\nEnter The Value you want to Add : ");
scanf("%d", &newnode->data);
newnode->next=temp;
backtemp->next=newnode;
break;
}
else if (temp->next == 0 && temp->data != num)
{
flagforerrormsg = 1;
break;
}
else if (temp->next == 0)
{
break;
}
else
{
if (temp->next == head)
{
temp = temp->next;
}
else
{
temp = temp->next;
backtemp = backtemp->next;
}
}
}
if (flagforerrormsg == 1)
{
printf("\nNo element as such type a number which is there or else......\n");
}
else
{
flagforstart++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment