#include <bits/stdc++.h>
using namespace std;
struct Node {
int data;
struct Node* next;
};
void delNodes(struct Node* head)
{
struct Node* current = head;
struct Node* maxnode = head;
struct Node* temp;
while (current != NULL && current->next != NULL) {
if (current->next->data >= maxnode->data) {
current = current->next;
maxnode = current;
}
else {
temp = current->next;
current->next = temp->next;
free(temp);
}
}
}
void push(struct Node** head_ref, int new_data)
{
struct Node* new_node = new Node;
new_node->data = new_data;
new_node->next = *head_ref;
*head_ref = new_node;
}
void printList(struct Node* head)
{
while (head != NULL) {
cout << head->data << " ";
head = head->next;
}
cout << endl;
}
int main()
{
struct Node* head = NULL;
push(&head;, 3);
push(&head;, 2);
push(&head;, 6);
push(&head;, 5);
push(&head;, 11);
push(&head;, 10);
push(&head;, 15);
push(&head;, 12);
printf("Given Linked List \n");
printList(head);
delNodes(head);
printf("Modified Linked List \n");
printList(head);
return 0;
}