Linked List basic type Codes, Study notes of Computer science

Codes for basic operations on linked list

Typology: Study notes

2024/2025

Uploaded on 04/20/2026

unknown user
unknown user 🇮🇳

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include <stdio.h>
#include <stdlib.h>
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;i<pos-1;i++)
{
current = current->next;
}
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;
}
}
pf3
pf4

Partial preview of the text

Download Linked List basic type Codes and more Study notes Computer science in PDF only on Docsity!

#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(); }