Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct Node
- {
- int data;
- struct Node *next;
- }*head;
- void createlinklist(int n);
- void display();
- void maxmin();
- int main()
- {
- int n;
- printf("Enter the number of nodes: ");
- scanf("%d",&n);
- createlinklist(n);
- printf("\nData entered in the list are:\n");
- display();
- maxmin();
- return 0;
- }
- void createlinklist(int n)
- {
- struct Node *p, *temp;
- int data, i;
- head= (struct Node*)malloc(sizeof(struct Node));
- printf("Input data for node 1: ");
- scanf("%d",&data);
- head->data=data;
- head->next=NULL;
- p=head;
- temp=head;
- for(i=2; i<=n; i++)
- {
- printf("Enter data for node %d: ",i);
- scanf("%d",&data);
- temp=(struct Node*)malloc(sizeof(struct Node));
- temp->data=data;
- temp->next=NULL;
- p->next=temp;
- p=p->next;
- }
- }
- void display()
- {
- struct Node *temp;
- temp=head;
- while(temp!=NULL)
- {
- printf("%d\n",temp->data);
- temp=temp->next;
- }
- }
- void maxmin()
- {
- struct Node *temp;
- temp=head;
- int max,min;
- max=temp->data;
- min=temp->data;
- while(temp!=NULL)
- {
- if(temp->data>max)
- {
- max=temp->data;
- }
- if(temp->data<min)
- {
- min=temp->data;
- }
- temp=temp->next;
- }
- printf("Maximum element is : %d\n",max);
- printf("Minimum element is : %d\n",min);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement