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

Linked List Total Program in C

This C program implements a linked list data structure with functions to create nodes, insert nodes at the beginning and end of the list, search for a value, delete the first node, and display the list. The main function contains a menu-driven loop that allows the user to select which linked list operation to perform and prompts for any required input values. Pointers are used to dynamically allocate memory for new nodes and link them together into a singly linked list.

Uploaded by

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

Linked List Total Program in C

This C program implements a linked list data structure with functions to create nodes, insert nodes at the beginning and end of the list, search for a value, delete the first node, and display the list. The main function contains a menu-driven loop that allows the user to select which linked list operation to perform and prompts for any required input values. Pointers are used to dynamically allocate memory for new nodes and link them together into a singly linked list.

Uploaded by

Sourav Gayen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

//LINKED LIST TOTAL PROGRAM IN C

#include<stdio.h>
#include<conio.h>
struct Node
{
int data;
struct Node* next;
};

typedef struct Node Node;


Node *start,*newptr,*save_st,*save_end,*ptr;
struct Node* Create_New_Node(int);
void Insert_Beg(struct Node*);
void Insert_End(struct Node*);
void Display(struct Node*);
void Search_value(struct Node*,int);
void Delete_Beg(void);

int main()
{
int val,choice;
char ch='y';
start=NULL;
newptr=NULL;
clrscr();
do
{
printf("\n1. Create");
printf("\n2. Insert at Beginning Position");
printf("\n3. Insert at Ending Positin");
printf("\n4. Searching a value...");
printf("\n5. Delete a node from begining Positin");
printf("\n6. Delete a node from Ending Positin");
printf("\n7. Display");
printf("\nEnter Your Choice");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("\n Enter a value");
scanf("%d",&val);
newptr=Create_New_Node(val);
if(newptr==NULL)
{
printf("\n Memory Is FULL");
exit(0);
}
else
printf("\n Node Create Successfully");
break;
case 2:if(newptr==NULL)
printf("\n Node Not Created");
else
Insert_Beg(newptr);
break;
case 3:if(newptr==NULL)
printf("\n Node Not Created");
else
Insert_End(newptr);
break;
case 4:printf("\n Enter a value for searching..");
scanf("%d",&val);
Search_value(start,val);
break;
case 5:Delete_Beg();
break;
case 7: Display(start);
break;
default:printf("\n Wrong Choice");
}//end of switch statement
printf("\n Do you want to continue(y/Y)?");
fflush(stdin);
scanf("%c",&ch);

}while(ch=='y'|| ch=='Y');//end of while

return 0;
}// end of main

/*************CODE FOR CREATING A NODE*************/

struct Node * Create_New_Node(int n)


{
ptr=(Node *)malloc(sizeof(Node));
ptr->data=n;
ptr->next=NULL;
return ptr;
}
/*************************************************/
/***********CODE FOR INSERT A NODE AT BEGINING POSITIO*****/
void Insert_Beg(Node * np)
{
if(start==NULL)
{
start=np;
save_end=np;
}
else
{
save_st=start;
start=np;
np->next=save_st;
}
printf("\n Your node insert successfully at begining position");
printf("\nAfter Insertion the list is as follows..");
Display(start);

}
/*****************************************************************/
/*******CODE FOR INSERT A NODE AT ENDING POSITION**********/
void Insert_End(Node *np)
{
if(start==NULL)
{
start=np;
save_end=np;
}
else
{
save_end->next=np;
save_end=np;
}
printf("\n Your node insert successfully at ending position");
printf("\nAfter Insertion the list is as follows..");
Display(start);

}
/*****************************************************************/
/*****CODE FOR SEARCHING A VALUE FROM THE LINKED LIST***/
void Search_value(struct Node* st,int v)
{
int temp=0;
while(st!=NULL)
{
if(st->data==v)
{
temp=1;
break;
}
st=st->next;
}
if(temp==1)
printf("\n Your Entered Number %d is Found",v);
else
printf("\n Sorry!!!!Your Entered Number %d is Not Found",v);
}
/*****************************************************************/
/************DELETE THE NODE FROM THE FIRST POSITION*****/
void Delete_Beg()
{
struct Node * np;
int val;
np=start;
val=np->data;
start=start->next;
free(np);
printf("\n Than You...Your First Node %d is deleted",val);
printf("\n After Deletion the Linked List is as Follows...");
Display(start);
}
/****************************************************************/
/***********DISPLAY THE LINKED LIST************/
void Display(Node *np)
{
while(np!=NULL)
{
printf("%d->",np->data);
np=np->next;
}
}
/*********************************************************/

You might also like