Linked List
Inserting a node at beginning
#include<stdlib.h>
#include<stdio.h>
struct node {int data;struct node* next;
};
struct node* head;
void insert(int x)
{node* temp = (node*)malloc(sizeof(struct node));if (temp == NULL) {printf("Memory allocation failed!\n");return;}temp->data = x;temp->next = head;head = temp;
}void print()
{struct node* temp = head;printf("list is:");while (temp != NULL){printf(" %d", temp->data);temp = temp->next;}printf("\n");
}
int main()
{head = NULL;insert(2);print();insert(100);insert(99);print();return 0;
}