


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Codes for basic operations on linked list
Typology: Study notes
Uploaded on 04/20/2026
1 / 4
This page cannot be seen from the preview
Don't miss anything!



#include #include void insert(int pos, int x); void insertbig(int x); void insertend(int x); void deletepos(int pos); void delbig(); void delend(); void print(); struct node { int data; struct node* next; }; struct node* head; void insert(int pos, int x) { int i; struct node* temp = (struct node)malloc(sizeof(struct node)); struct node* current = head; temp->data=x; temp->next=NULL; if(pos == 1) { temp->next = head; head = temp; return; } for(i=1;inext; } temp->next = current->next; current->next = temp; } void insertbig(int x) { struct node* temp =(struct node)malloc(sizeof(struct node)); temp->data = x; temp->next = NULL; if(head == NULL) { head = temp; } else { temp->next = head; head = temp; } }
void insertend(int x) { struct node* temp =(struct node)malloc(sizeof(struct node)); struct node* current = head; temp->data = x; temp->next = NULL; if(head == NULL) { head = temp; } else { while(current->next != NULL) { current = current->next; } current->next = temp; } } void delbig() { struct node* current = head; if(head == NULL) { return; } else { current=current->next; head = current; } } void delend() { struct nodecurrent = head; // struct nodeprevious = head; while(current->next->next != NULL) { current=current->next; } current->next=NULL; } void deletepos(int pos) { struct node* current = head; struct node* previous = head; int i; if(head==NULL) { return;
printf("Enter value to insert in bigining\n"); scanf("%d",&va); insertbig(va); print(); printf("Enter position to delete\n"); scanf("%d",&de); deletepos(de); print(); getch(); }