sp-linked-list
https://practice.geeksforgeeks.org/tracks/sp-linked-list/?batchId=152
Problems
void display(Node *head)
{
while (head != NULL) {
cout << head->data << " ";
head = head->next;
}
}// function inserts the data in front of the list
Node *insertAtBegining(Node *head, int newData) {
struct Node *temp=new Node(newData);
if (head == NULL) {
head = temp;
} else {
temp->next = head;
head = temp;
}
return head;
}
// function appends the data at the end of the list
Node *insertAtEnd(Node *head, int newData) {
struct Node *newNode =new Node(newData);
Node *temp=head;
if (head == NULL) {
head = newNode;
} else {
while (temp->next !=NULL) {
temp=temp->next;
}
temp->next = newNode;
}
return head;
}Last updated