struct node
{
int data;
struct node *link;
} *head;
void add_beginning (int num) {
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));
temp ->data = num;
temp ->link = NULL;
if (head == NULL) {
head = temp;
}
else {
temp ->link = head;
head = temp;
}
}
void add_end (int num) {
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));
temp ->data = num;
temp ->link = NULL;
if (head == NULL){
head = temp;
}
else {
right = (struct node *)head;
while(right ->link != NULL)
right = right ->link;
right ->link = temp;
}
}
Void add_middle (int c, int num){
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));
temp ->data = num;
temp ->link = NULL;
if (head == NULL){
head = temp;
}
else {
struct node *right, *right1;
right = head;
right1 = head;
for (int i = 0; i <c; i++)
right = right ->link;
right1 = right ->next;
right ->next = temp;
temp ->next = right1;
}
}