0% found this document useful (0 votes)
11 views4 pages

Linked List Prgrams

Uploaded by

dumbthings1729
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Linked List Prgrams

Uploaded by

dumbthings1729
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <stdio.

h>

#include <stdlib.h>

struct node {

int data;

struct node*link;

};

void addatend(struct node*head,int value){

struct node* new=malloc(sizeof(struct node));

new->data=value;

new->link=NULL;

struct node*ptr=head;

while(ptr->link!=NULL){

ptr=ptr->link;

ptr->link=new;

void insertatpos(struct node*head,int value,int prev_val){

struct node* new=malloc(sizeof(struct node));

new->data=value;

new->link=NULL;

struct node*ptr= head;

while(ptr!=NULL){

if (ptr->data==prev_val){

new->link=ptr->link;

ptr->link=new;

break;

ptr=ptr->link;
}

void insert(struct node*head,int pos,int value){

struct node*current=head;

struct node*new=malloc(sizeof(struct node));

new->data=value;

new->link=NULL;

pos--;

while(pos!=1){

current=current->link;

pos--;

new->link=current->link;

current->link=new;

void delatpos(struct node**head,int pos){

struct node*prev=*head;

struct node*current=*head;

if (*head==NULL){

"List is empty";

else if(pos==1){

*head=current->link;

free(current);

current=NULL;

else{

while(pos!=1){
prev=current;

current=current->link;

pos--;

prev->link=current->link;

free(current);

current=NULL;

int main() {

struct node* head=malloc(sizeof(struct node));

head->data=23;

head->link=NULL;

struct node*current = malloc(sizeof(struct node));

current->data=67;

current->link=NULL;

head->link=current;

addatend(head,28);

addatend(head,58);

addatend(head,98);

addatend(head,19);

addatend(head,33);

insertatpos(head,4,58);

insertatpos(head,2,33);

insert(head,2,1);

delatpos(&head,9);

struct node*ptr=head;

while(ptr!=NULL){

printf("%d \t",ptr->data);
ptr=ptr->link;

return 0;

You might also like