Provide a member function of class linkedListType that determines the maximum element in a list. Use the following header template Type linkedListType:: max(); You may assume that operator> is overloaded for Type.
using namespace std;
#include <omp.h>
#include <stdio.h>
struct Node
{
int data;
struct Node *next;
};
struct Node* head = NULL;
void InsertData(int NewtData)
{
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
new_node->data = NewtData;
new_node->next = head;
head = new_node;
}
void DisplayLinkedList(void)
{
struct Node* ptr; ptr=head;
while (ptr != NULL)
{
cout<< ptr->data <<" ";
ptr = ptr->next;
}
}
void max(void)
{
struct Node* ptr; ptr=head;
int Max;
Max = ptr->data;
while (ptr != NULL)
{
if(ptr->data >= Max) Max = ptr->data;
ptr = ptr->next;
}
cout<<"\nMaximum Element = "<<Max;
}
int main()
{
int List[5] = {1, 3, 5, 33, 22};
int n;
for(n=0;n<5;n++) InsertData(List[n]);
cout<<"\nThe linked list- is: ";
DisplayLinkedList();
max();
return 0;
}
Comments
Leave a comment