class Solution{
public:
//Function to insert a node at the beginning of the linked list.
Node *insertAtBegining(Node *head, int x)
{
Node* newnode=new Node(x);
newnode->next=head;
return newnode;
}
//Function to insert a node at the end of the linked list.
Node *insertAtEnd(Node *head, int x)
{
if(!head)
{
Node* newnode=new Node(x);
return newnode;
}
Node* temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
Node* newnode=new Node(x);
temp->next=newnode;
return head;
}
};