Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- #define max 20
- typedef struct node
- {
- int data;
- struct node *next;
- }node;
- typedef struct
- {
- node *start;
- }head;
- void insertend(head *t,int ele)
- {
- node *p,*q;
- p = (node*)malloc(sizeof(node));
- p->data=ele;
- p->next=NULL;
- if(t->start==NULL)
- {
- t->start=p;
- return;
- }
- q=t->start;
- while(q->next!=NULL)
- {
- q = q->next;
- }
- q->next = p;
- return ;
- }
- void count(head *t)
- {
- node *q;
- int c=0;
- if(t->start==NULL)
- {
- printf("Linked List is empty");
- return;
- }
- q=t->start;
- while(q!=NULL)
- {
- c=c+1;
- q=q->next;
- }
- printf("Total no. of elements in Linked list is %d",c);
- return;
- }
- void findmax(head *t)
- {
- int z;
- node *p;
- if(t->start==NULL)
- {
- printf("Linked list is Empty");
- return;
- }
- z = t->start->data;
- p = t->start->next;
- while(p->next!=NULL)
- {
- if(z<p->data)
- {
- z = p->data;
- }
- p = p->next;
- }
- printf("Maximum element in Linked list %d",z);
- return;
- }
- void display(head *t)
- {
- node *q;
- if(t->start==NULL)
- {
- printf("\nLinked list is empty");
- return;
- }
- q = t->start;
- printf("\nElement of Linked list is given below\n");
- while(q!=NULL)
- {
- printf("%d\t",q->data);
- q=q->next;
- }
- return;
- }
- int main()
- {
- head x;
- int ch,ele;
- printf("\nImplementation of Linked list with function insertend,display,findmax,count\n");
- while(1)
- {
- printf("\nenter choice \n1.InsertEnd 2.Findmax 3.Count 4.display 5.Exit\n");
- scanf_s("%d",&ch);
- if(ch==5)
- {
- break;
- }
- else
- {
- switch(ch)
- {
- case 1:printf("\nenter element to insert");
- scanf_s("%d",&ele);
- insertend(&x,ele);
- break;
- case 2:findmax(&x);
- break;
- case 3:count(&x);
- break;
- case 4:display(&x);
- break;
- default:printf("\ninvalid input");
- }
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement