0% found this document useful (0 votes)
26 views5 pages

Double Linked List

Uploaded by

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

Double Linked List

Uploaded by

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

DOUBLE LINKED LIST:-

#include <stdio.h>

#include <stdlib.h>

struct node

int data;

struct node *next;

struct node*pre;

} *stnode;

void creatlikedlist(int n)

struct node *fnnode, *tmp;

int num;

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

if (stnode == NULL)

printf("memory is emty :");

else

printf("input data of 1st node :");

scanf("%d", &num);

stnode->data = num;

// stnode->next = NULL;

tmp = stnode;

for (int i = 2; i <= n; i++)


{

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

if (fnnode == NULL)

printf("memory is emty :");

break;

else

printf("enter the %d node data = ", i);

scanf("%d", &num);

fnnode->data = num;

fnnode->next = NULL;

tmp->pre=fnnode;

tmp->next = fnnode;

tmp = tmp->next;

void display()

struct node*ptr;

if(stnode==NULL){

printf("memory is emty");

else{

ptr=stnode;

while(ptr!=NULL)

{
printf("\ndata=%d",ptr->data);

ptr=ptr->next;

struct node*insertAtbeginning(struct node*stnode)

struct node*new_node;

int num;

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

printf("\n\nenter the data that is insert at the beginning : ");

scanf("%d",&num);

new_node->data=num;

new_node->next=stnode;

new_node->pre=NULL;

stnode=new_node;

return stnode;

struct node*insertAtlast(struct node*stnode)

struct node*new_node,*ptr;

int num;

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

printf("\n\nenter the data that is insert at the last : ");

scanf("%d",&num);

new_node->data=num;

ptr=stnode;

while(ptr->next!=NULL){

ptr=ptr->next;
}

ptr->next=new_node;

new_node->pre=ptr;

new_node->next=NULL;

return stnode;

struct node*deleteAtbeg(struct node*stnode)

stnode=stnode->next;

stnode->pre=NULL;

return stnode;

struct node*deleteAtend(struct node*stnode)

struct node*ptr,*prev;

ptr=stnode;

while(ptr->next!=NULL){

ptr=ptr->next;

ptr->pre->next=NULL;

return stnode;

int main()

int n;

printf("enter the node numer : ");

scanf("%d",&n);
creatlikedlist(n);

display();

stnode=insertAtbeginning(stnode);

printf("\n\n\n insert after the beginning : ");

display();

stnode=insertAtlast(stnode);

printf("\n\n\n insert after the last : ");

display();

stnode=deleteAtbeg(stnode);

printf("\n\n\n deletion at beginning : ");

display();

stnode=deleteAtend(stnode);

printf("\n\ndeletion at END : ");

display();

return 0;

You might also like