Professional Documents
Culture Documents
Reg_no-18BCE1123
Digital Assignment -1
1.
Write a “C” function to insert a node “t” before a node pointed to by “X” in a single linked list “L”.
ANS-
#include <iostream>
struct Node {
int data;
};
int size = 0;
newNode->data = data;
newNode->next = NULL;
return newNode;
newnode->data = data;
newnode->next = NULL;
if (*head == NULL)
*head= newnode;
return;
}
last = last->next;
last->next = newnode;
return;
else
while (pos--)
if (pos == 0)
temp->next = *root;
*root = temp;
else
root = &(*root)->next;
size++;
{
cout << " " << root->data;
root = root->next;
int main()
int n,i,a[n];
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
push(&head,a[i]);
size = n;
int data,pos;
cin>>data;
cin>>pos;
print(head);
return 0;