Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List
OFLINE BATCH EMBEDDED:
PROGRAM:
#include<stdio.h>//HEADER FILE
#include<stdlib.h>//LIBRARY FUNCTIONS
struct node
{
int data;//VARIABLE DECLARATION
struct node *next;
};
void print(struct node *list);
int main()//MAIN FUNCTIONS
{
struct node *temp = NULL;//ASSUMING VARIABLES
struct node *head;
struct node *one = NULL;
struct node *two = NULL;
struct node *three = NULL;
one = malloc(sizeof(struct node));//MEMORY ALLOCATION
two = malloc(sizeof(struct node));
three = malloc(sizeof(struct node));
printf("one->data =");//WRITE OUTPUT ON THE CONSOLE
fflush(stdout);
scanf("%d",&one->data);//READ OUTPUT OF THE CONSOLE
printf("two->data =");
fflush(stdout);
scanf("%d",&two->data);
printf("three->data =");
fflush(stdout);
scanf("%d",&three->data);
one->next = two;
two->next = three;
three->next = NULL;
head = one;
struct node *four = NULL;//INSERTION OF ANOTHER NODE
four = malloc(sizeof(struct node));//MEMORY SIZE OF FOURTH NODE
printf("\n four->data =");
fflush(stdout);
scanf("%d",&four->data);
three->next = four;
four->next = NULL;
print(head);
printf("\n");
head = head->next;
free(one);
head = two;
print(head);
}
void print(struct node *list)
{
while (list!=NULL)//CONDITTION STATEMENT
{
printf("%d",list->data);
list=list->next;
}
}