From 8b8ec0d449daa4ffe55c38f9254c55bb616c6b2c Mon Sep 17 00:00:00 2001 From: Stuti Chauhan <47496834+dulcetsoul@users.noreply.github.com> Date: Tue, 1 Oct 2019 01:46:11 +0530 Subject: [PATCH] to find the maximum and minimum element in a link list --- 1..txt | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 1..txt diff --git a/1..txt b/1..txt new file mode 100644 index 0000000..b4ae6f3 --- /dev/null +++ b/1..txt @@ -0,0 +1,87 @@ +// Find maximum and minimum elements of linked list + +#include +using namespace std; + +struct node{ + int data; + struct node *next; +}*newptr,*temp,*ptr,*start; + +node* Create(int n) +{ + ptr = new node; + ptr->data = n; + ptr->next = NULL; + return ptr; +} +void Insert(node* np) +{ + if(start == NULL) + { + start = np; + } + else + { + temp = start; + start = np; + np->next = temp; + } +} +void Display(node *np) +{ + ptr = np; + int high=ptr->data; + int low=ptr->data; + while(np!= NULL) + { + + + if(highdata) + { + high = np->data; + } + np = np->next; + } + cout<<"The maximum element is \n"; + cout<np->data) + { + low = np->data; + } + np = np->next; + } + cout<<"\nThe minimum element is \n"<>inf; + newptr = Create(inf); + if(newptr== NULL) + { + cout<<"No memory can be allocated"; + break; + } + else + { + cout<<"Now inserting this node in the beginning of the list...\n"; + Insert(newptr); + } + cout<<"Do u wanna continue..\n"; + cin>>ch; + } + cout<<"Elements in the lists are :...\n"; + Display(start); + return 0; + +}