Single Linked List
Single Linked List
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *head, *tail = NULL;
void addNode(int data) {
struct node *newNode = (struct node*)malloc(sizeof(struct node));
newNode->data = data;
newNode->next = NULL;
if(head == NULL) {
head = newNode;
tail = newNode;
}
else {
tail->next = newNode;
tail = newNode;
}
}
void display() {
struct node *current = head;
if(head == NULL) {
printf("List is empty\n");
return;
}
printf("Nodes of singly linked list: \n");
while(current != NULL) {
printf("%d ", current->data);
current = current->next;
}
printf("\n");
}
int main()
{
Output:
Nodes of singly linked list:
20 2 36 45
Output:
printing values . . . . .
20
2
36
45
Output:
Linked list before insertion: 1 2 3 4 5
Output:
Nodes of singly linked list: 20 2 36 45
Output:
Nodes of singly linked list: 20 2 36 45
#include <stdio.h>
#include <stdlib.h>
void insert(int);
void display_List();
void delete (int);
Output:
--Created Linked List--
int main() {
struct Node *poly1 = NULL, *poly2 = NULL, *result = NULL;
// Creating first polynomial: 3x^3 + 5x^2 + 6
Output:
Polynomial 1: 3*x^3 + 5*x^2 + 6
Polynomial 2: 4*x^3 + 2*x + 7
Resultant Polynomial after Addition: 7*x^3 + 5*x^2 + 2*x + 13