Singly Linked List

zhumpex (12)
Can anyone help me?

I want to insert data before head.

example :
3 4 5
I want insert 2 before 3,,but I get an error in C++ program.

This is my script

void insert_before(int s)
{
Node *before=head;
if(before->next->Data!=s) { //Example. Data = 2 and s = 3 4 5
printf("\nERROR\n");
}
else {
new->next=before->next;
before->next=new;
}
}
vlad from moscow (3662)
I do not see where you create a new Node for the inserted data.
Show the definition of the Node.
faishalmovic13 (2)
may be, this can help you http://faishalmovic13.wordpress.com/2012/11/01/single-linked-list1/
Topic archived. No new replies allowed.