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 DeleteNode(struct node **head, int k)
{
struct node *temp;
if(*head->data == k)
{
temp = *head;
*head = (*head)->next;
free(temp);
}
}
int SearchLinkedList(int dat)
{
int Flag=0;
struct Node* ptr; ptr=head;
while (ptr != NULL)
{
if(ptr->data == dat)
{
cout<< ptr->data <<" ";
Flag=1;
}
ptr = ptr->next;
}
return(Flag);
}
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