web123456

Design an algorithm to determine the largest node in a single linked list through a traversal

#include <iostream>
 using namespace std;
 typedef int Status;
 typedef int elemtype;
 #define OK 1
 #define ERROR 0
 typedef struct LNode
 {
	 elemtype data;
	 struct LNode *next;
 }LNode,*LinkList;

 void CreateList_L(LinkList &L,int n)
 { int i;
     LNode *r,*p;
	 L=new LNode;
	 L->next=NULL;
	 r=L;
	 cout<<"Please enter element: \n";
	 for(i=0;i<n;++i)
	 {
		 p=new LNode;
		 cin>>p->data;
		 p->next=NULL;
		 r->next=p;
		 r=p;
	 }
 }
 void Maxelem_L(LinkList &L)
 {
	 int max,i=0;
	 LNode *p=L->next;
	 max=p->data;
	 While(p)
	 {
		 if(p->data>max)
		    max=p->data;
         p=p->next;
	 }
	 p=L->next;
	 While(p)
	 { i++;
		 if(p->data==max)
		    cout<<"Th"<<i<<"node, "<"value is"<<p->data<<endl;
         p=p->next;
	 }
	 cout<<endl;
 }
 int main()
 { int n1;
	 LNode *la;
	
	 cout<<"Please enter the number of elements in the linear table: ";
	 cin>>n1;
	 CreateList_L(la,n1);
	 cout<<"The node with the largest value in the linked list is: \n";
	 Maxelem_L(la);
	 return 0;
 }