#include <stdio.h>
struct list
{
int data;
struct list *next;
};
typedef struct list node;
void insert(node *head)
{
node *temp,*last,*start=head;
temp=(node *)malloc(sizeof(node));
printf("Enter Value: ");
scanf("%d",&temp->data);
temp->next=NULL;
if(start==NULL)
{
start = temp;
head = temp;
}
else
{
last = start;
while(last->next!=NULL)
{
last = last->next;
}
last->next= temp;
}
menu(head);
}
void find_even(node *head)
{
node *start=head;
if(start==NULL)
{
printf("No Data Found");
menu(head);
}
else
{
printf("All Even Number: ");
while(start!= NULL)
{
if(start->data%2==0)
{
printf("%d ",start->data);
start= start->next;
}
else
{
start = start->next;
}
}
printf("");
menu(head);
}
}
void find_odd(node *head)
{
node *start=head;
if(start==NULL)
{
printf("No Data Found");
menu(head);
}
else
{
printf("All Odd Number: ");
while(start!= NULL)
{
if(start->data%2!=0)
{
printf("%d ",start->data);
start= start->next;
}
else
{
start = start->next;
}
}
printf("");
menu(head);
}
}
void total_node(node *head)
{
node *start=head;
int count=0;
if(start==NULL)
{
printf("No Data Found");
menu(head);
}
else
{
while(start != NULL)
{
count++;
start= start->next;
}
printf("Total Node: %d",count);
menu(head);
}
}
void find_max(node *head)
{
node *start = head;
int max= start->data;
if(start==NULL)
{
printf("No Data Found");
menu(head);
}
else
{
while(start!=NULL)
{
if(start->data>max)
{
max = start->data;
start = start->next;
}
else
{
start = start->next;
}
}
printf("Max: %d",max);
menu(head);
}
}
void find_min(node *head)
{
node *start = head;
int min= start->data;
if(start==NULL)
{
printf("No Data Found");
menu(head);
}
else
{
while(start!=NULL)
{
if(start->data<min)
{
min = start->data;
start = start->next;
}
else
{
start = start->next;
}
}
printf("Min: %d",min);
menu(head);
}
}
void print(node *head)
{
node *start = head;
if(start==NULL)
{
printf("No Data Found");
menu(head);
}
else
{
printf("Your Linked List: ");
while(start != NULL)
{
printf("%d ",start->data);
start = start->next;
}
printf("");
menu(head);
}
}
void end()
{
printf("a!! The End !!");
return 0;
}
void menu(node *head)
{
int flag;
printf("1.Press 1 to Insert2.Press 2 For Find Even Number3.Press 3 For Find Odd Number4.Press 4 For Total Node5.Press 5 For Max Value6.Press 6 For Min Value7.Press 7 For Print8.Press 0 to ExitEnter Your Choice: ");
scanf("%d",&flag);
if(flag==1)
{
insert(head);
}
else if(flag==2)
{
find_even(head);
}
else if(flag==3)
{
find_odd(head);
}
else if(flag==4)
{
total_node(head);
}
else if(flag==5)
{
find_max(head);
}
else if(flag==6)
{
find_min(head);
}
else if(flag==7)
{
print(head);
}
else if(flag==0)
{
end();
}
}
int main()
{
node *head;
head= NULL;
menu(head);
return 0;
}
Output
1.Press 1 to Insert
2.Press 2 For Find Even Number
3.Press 3 For Find Odd Number
4.Press 4 For Total Node
5.Press 5 For Max Value
6.Press 6 For Min Value
7.Press 7 For Print
8.Press 0 to Exit
Enter Your Choice: 1
Enter Value: 3
1.Press 1 to Insert
2.Press 2 For Find Even Number
3.Press 3 For Find Odd Number
4.Press 4 For Total Node
5.Press 5 For Max Value
6.Press 6 For Min Value
7.Press 7 For Print
8.Press 0 to Exit
Enter Your Choice: 0
!! The End !!
Add your comment