Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List
#include <stdio.h>
#include<stdlib.h>
struct node{
int value;
struct node *next;
};
void printlinkedlist(struct node *p)
{
while(p!=NULL)
{
printf("%d\t",p->value);
p=p->next;
}
}
int main()
{
struct node *head;
struct node *one=NULL;
struct node *two=NULL;
struct node *three= NULL;
one=malloc(sizeof(struct node));
two=malloc(sizeof(struct node));
three=malloc(sizeof(struct node));
one->value=1;
two->value=2;
three->value=3;
one->next=two;
two->next=three;
three->next=NULL;
head=one;
printlinkedlist(head);
printf("\n");
struct node *four=NULL;
four=malloc(sizeof(struct node));
four->value=4;
three->next=four;
four->next=NULL;
printlinkedlist(head);
printf("\n");
one->next=two;
two->next=NULL;
printlinkedlist(head);
return 0;
}
output: 1 2 3
1 2 3 4
1 2