#include
using namespace std;
int insertatbeg(int data,struct node *head,struct node newnode);//function declaration
int main(){
struct node{
int data;
struct nodenext;
};
int choice=1;
struct nodehead=NULL,newnode,temp;
while(choice){
newnode=(struct node)malloc(sizeof(struct node));
cin>>newnode->data;
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else {
newnode->next = head;
head = newnode;
}
cout<<“do you want to continue”<<endl;
cin>>choice;
}
temp=head;
while(temp!=0)
{
cout<data;//printing linkedlist
temp=temp->next;
}
insertatbeg(data,head,newnode);//function calling
cout<data;//printing data of new node at first
temp=head;//now printing the previous linked list followed by newnode
while(temp!=0)
{
cout<data;
temp=temp->next;
}
}
int insertatbeg(int data, struct nodehead,struct nodenewnode)//function defination
{
cin>>newnode->data;
newnode->next=head;
head=newnode;
}
/Errors:
main.cpp: In function ‘int main()’:
main.cpp:33:13: error: ‘data’ was not declared in this scope
insertatbeg(data,head,newnode);//function calling
^~~~
main.cpp: In function ‘int insertatbeg(int, node, node*)’:
main.cpp:44:17: error: invalid use of incomplete type ‘struct node’
cin>>newnode->data;
^~
main.cpp:3:33: note: forward declaration of ‘struct node’
int insertatbeg(int data,struct node *head,struct node *newnode);//function declaration
^~~~
main.cpp:45:12: error: invalid use of incomplete type ‘struct node’
newnode->next=head;
^~
main.cpp:3:33: note: forward declaration of ‘struct node’
int insertatbeg(int data,struct node *head,struct node *newnode);//function declaration
^~~~
*/