SINGLY LINEAR LINK LIST

548

 

BCA Third Semester

Singly Linear link list

data structure

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct link
{
int data;
struct link *next;
};struct link *nw, *head, *tail, *temp1, *temp2;

void insert_begin();
void insert_middle();
void insert_end();
void delete_begin();
void delete_middle();
void delete_end();
void display();

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. Disple\n8. Exit\n\n “);
printf(“Enter Your Choice : “);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
insert_begin();
break;
case 2:
insert_middle();
break;
case 3:
insert_end();
break;
case 4:
delete_begin();
break;
case 5:
delete_middle();
break;
case 6:
delete_end();
break;
case 7:
display();
break;
case 8:
printf(“Thank U”);
break;

}

}while(ch != 8);
}

///////////////////////////////////////////
void insert_begin()
{
int item;
clrscr();
nw=(struct link *)malloc(sizeof (struct link));
printf(“Enter the Data of Node : “,&item);
scanf(“%d”,&item);
nw -> data = item;
nw -> next = head;
head = nw;
}

void insert_middle()
{
int item,pos,i;
clrscr();
temp1=head;
temp2=head;
printf(“Enter the positon : “);
scanf(“%d”,&pos);
printf(“Enter the Data of Node : “);
scanf(“%d”,&item);
for(i=1;i<pos-1;i++)
{
temp1 = temp1->next;
}
temp2=temp1->next;
nw = (struct link *)malloc(sizeof (struct link));
nw -> data = item;
nw -> next = temp2;
temp1 -> next = nw;
printf(“node enerd “);
getch();
}

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

void delete_begin()
{
struct link *temp;
clrscr();
temp = head;
head = head->next;
printf(“%d Node is Deletion”,temp->data);
free(temp);

getch();
}

void delete_middle()
{
int pos,i;
clrscr();
printf(“Enter Position : “);
scanf(“%d”,&pos);
temp1 = head;
temp2 = head;
for(i=1;i<pos-1;i++)
{
temp1 = temp1 -> next;
}
temp2 = temp1 -> next;
temp1 -> next = temp2 -> next;
free(temp2);

}

void delete_end()
{
clrscr();
temp1 = head;
while(temp1->next != NULL)
{
temp2=temp1;
temp1 = temp1 -> next;
}
printf(“%d Node is Delete.”,temp1->data);
free(temp2->next);
temp2->next = NULL;
getch();
}

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

 

 

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