Exercise 3 4
Exercise 3 4
struct Node
{
int data;
struct Node* next;
} *head = NULL;
void removeDuplicates()
{
struct Node *current = head, *prev, *temp;
void display()
{
if (head == NULL)
{
printf("List is empty.\n");
return;
}
struct Node* temp = head;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
int main()
{
insertion(1, 10);
insertion(2, 10);
insertion(3, 10);
insertion(4, 20);
insertion(5, 40);
insertion(6, 20);
printf("Original list:\n");
display();
removeDuplicates();
printf("List after removing duplicates:\n");
display();
return 0;
}
ii) Implement a linked list to represent polynomials and perform addition.
SOURCE CODE:
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int coeff;
int expo;
struct Node* next;
}*head=NULL;
newNode->next = temp->next;
temp->next = newNode;
return head;
}
return result;
}
// Main function
int main() {
struct Node* poly1 = NULL;
struct Node* poly2 = NULL;
struct Node* sum = NULL;
return 0;
}
void display()
{
if (head == NULL)
{
printf("List is empty.\n");
return;
}
struct Node* temp = head;
while (temp != NULL)
{
printf("%d <-> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
int main()
{
int choice, value, pos;
while (1)
{
printf("\n1. Insert\n2. Delete\n3. Display\n4. Exit\nEnter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1: printf("Enter value and position: ");
scanf("%d %d", &value, &pos);
insertion(pos, value);
break;
case 2: printf("Enter value to delete: ");
scanf("%d", &value);
deletion(value);
break;
case 3: display();
break;
case 4: return 0;
default:printf("Invalid choice! Please try again.\n");
}
}
}
ii) Implement a circular linked list and perform insertion, deletion, and traversal.
SOURCE CODE:
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node* next;
} *head = NULL;