#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node* insertEnd(struct node *head, int data)
{
struct node *newnode, *temp;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->data = data;
newnode->next = NULL;
if(head == NULL)
return newnode;
temp = head;
while(temp->next != NULL)
temp = temp->next;
temp->next = newnode;
return head;
}
struct node* reverse(struct node *head)
{
struct node *prev = NULL;
struct node *current = head;
struct node *next;
while(current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
return prev;
}
struct node* merge(struct node *head1, struct node *head2)
{
struct node *temp;
if(head1 == NULL)
return head2;
temp = head1;
while(temp->next != NULL)
temp = temp->next;
temp->next = head2;
return head1;
}
void removeDuplicates(struct node *head)
{
struct node *current, *temp, *duplicate;
current = head;
while(current != NULL)
{
temp = current;
while(temp->next != NULL)
{
if(temp->next->data == current->data)
{
duplicate = temp->next;
temp->next = temp->next->next;
free(duplicate);
}
else
{
temp = temp->next;
}
}
current = current->next;
}
}
void display(struct node *head)
{
while(head != NULL)
{
printf("%d -> ", head->data);
head = head->next;
}
printf("NULL\n");
}
int main()
{
struct node *head1 = NULL;
struct node *head2 = NULL;
head1 = insertEnd(head1, 10);
head1 = insertEnd(head1, 20);
head1 = insertEnd(head1, 20);
head1 = insertEnd(head1, 30);
head2 = insertEnd(head2, 40);
head2 = insertEnd(head2, 50);
printf("Original List:\n");
display(head1);
head1 = reverse(head1);
printf("Reversed List:\n");
display(head1);
removeDuplicates(head1);
printf("After Removing Duplicates:\n");
display(head1);
head1 = merge(head1, head2);
printf("After Merging:\n");
display(head1);
return 0;
}⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.