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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy