DOUBLY LINKED LIST

565

bca third semester

doubly linked list

data structure program

 

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
int pos,i,n,item;
struct doubly
{
int data;
struct doubly *pre, *next;
}; struct doubly *head, *tail, *temp, *temp1, *temp2, *nw;

void insert_b()
{
int item;
clrscr();
printf(“Enter Item : “);
scanf(“%d”,&item);
nw = (struct doubly *)malloc(sizeof(struct doubly));
nw -> data = item;
nw -> pre = NULL;
nw -> next = head;
head ->pre = nw;
head = nw;
}

void insert_e()
{
int item;
clrscr();
printf(“Enter Item : “);
scanf(“%d”,&item);
while(temp->next != NULL)
{
temp = temp -> next;
}

nw = (struct doubly *)malloc(sizeof(struct doubly));
nw -> data = item;
temp -> next = nw;
nw ->pre = temp;
temp = nw;
nw ->next = NULL;
}

void insert_m()
{
temp1=head;
temp2=head;
clrscr();
printf(“Enter Your Position : “);
scanf(“%d”,&pos);
printf(“Enter Item : “);
scanf(“%d”,&item);
for(i=1;i next;
}
temp2=temp1 -> next;

nw = (struct doubly *)malloc(sizeof(struct doubly));
nw -> data = item;
temp1 -> next = nw;
nw -> next = temp2;
temp2 -> pre = nw;
nw -> pre = temp1;
}

void delete_b()
{
clrscr();
temp = head;
head = head ->next;
printf(“%d is deleted.”,temp->data);
free(temp);
head -> pre = NULL;
getch();
}

void delete_e()
{
clrscr();
temp = head;
while(temp->next->next != NULL)
{
temp =temp->next;
}
printf(“%d is deleted.”,temp->next->data);
free(temp->next);
tail = temp;
temp -> next = NULL;
getch();

}

void delete_m()
{
clrscr();
temp1 = head;
temp2 = head;
printf(“Enter Positon : “);
scanf(“%d”,&pos);
for(i=1;inext;
}
temp2 = temp1 -> next;
temp1->next = temp2->next;
printf(“%d position %d is deleted.”,pos,temp2->data);
free(temp2);
temp1->next->pre = temp1 ->next;
getch();
}

void display()
{
temp= head;
while(temp->next!= NULL)
{
printf(“\n\t%d”,temp->data);
temp= temp->next;
}
printf(“\n\t%d”,temp->data);
}

void main()
{
int item,ch;
do
{
clrscr();
printf(“1. Insert Node of Beginning : \n2. Insert Node of middle any Posistion\n3. Insert Node of Ending : \n4. Delete Node of Beginning\n5. Delete Node of middle any position\n6. Delete Node of Ending\n7. Display\n8. Exit\n\n “);
printf(“Enter Your Choice : “);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
insert_b();
break;
case 2:
insert_m();
break;
case 3:
insert_e();
break;
case 4:
delete_b();
break;
case 5:
delete_m();
break;
case 6:
delete_e();
break;
case 7:
clrscr();
display();
getch();
break;
case 8:
printf(“Thank U”);
break;

}
}while(ch != 8);
}

 

 

 

if you need a Downloadable link once message us on-page you can get at a time.

m.me/bcanotesnepal

This post is posted for not further third-party purposes.

Copyright By:-  Bcanotesneapl

Not allowed to upload these notes to other sites.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

if you want to download this PDF comment on us we will provide you a downloadable link.

if you like please share this post with your friend who studies in BCA

if you have any query please comment below,

if you like our sites. you can visit again for the latest updates notes of different BCA subjects of Presentation and different topics with assignment questions and solutions.

Don’t forget to like our page and post also share with your friend and having your group.

if you have any questions you can drop or share them with me using the comment box I will try to answer your question.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

LEAVE A REPLY

Please enter your comment!
Please enter your name here