Challenge

Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List

#include
#include

struct node {

	 int data;
	 struct node *next;
	};
    struct node *inter = NULL;          // create a node pointer to store intersection 
                                        //node list that is new node list
    struct node   *union_list = NULL;

struct node* intersection(struct node *head, struct node *head1) {
                     // defination of function to execute a intersection some conditions
                             
	     
        inter = NULL;        //  firs initialize the pointer that pointer to 
                            // to hold or save the intersection value or data 

         while(head != NULL){     // in a while loop  run up to first list of data can 
                                  // not end or zero  
        
   if(ispresent(head1, head->data))  // in this step to check the list one data it is 
                                        availabe or not of second linked list conditions
 {
   insert(&inter, head->data);        // if the  present function is true when that time 
                                       //  insert function is calling  
   }
    head = head->next;
    }

}
void findunion(struct node *head, struct node *head1) {  
                                             // defination of union function 
    union_list = NULL;                    
                                           // to perform the union operation
 
        struct node *ptr = head;  
   
 while(ptr != NULL){            // trensfer all nodes list one pointer head to 
                                // another pointer that is  union_list in a while loop 
 
 insert(&union_list, ptr->data); // trensfer all nodes list of data one list first to 
                                 
                               //  another list that is  union_list  
        ptr = ptr->next;
    }

    while(head1 != NULL)    
    {
        if(!ispresent(head, head1->data)){    // this condition to check the data or 
                                            //  value present or not in union list
            insert(&union_list, head1->data);   // present function condition its true 
                                           // than insert function can be execute 
        }
        head1= head1->next;
    }

}

void insert(struct node **head, int num)
    {

    struct node *newNode =  malloc(sizeof(struct node));   // allocate memory for create 
                                    // a new node to store data of bothe node list 

    newNode->data  = num;                //  created new node data pointer to the data 
                                       // of comman value to bothe node 


    newNode->next = *head;        

    *head = newNode;
}

void printlinkedlist(struct node *a )     // create a function to print the all node list
 {

		while(a != 0 )  //  condition for to move valu of node end of node or 
                                 //not equal to null
		{

		 printf("%d ",a->data);
		 a=a->next;
		}
	}
 int ispresent(struct node *node, int num) {
    while (node != NULL) {     
        if (node->data == num){   // check the all value of second node list to compare 
                                  //  first node data value
           return 1;
        }
        node = node->next;
    }
    return 0;
}


int main()              // in a main () function its  the starting of the program 
   {

        struct node *head;       // declare a struct type pointer to create node and 
	struct node *one=0;       // final create a link list of data
	struct node *two=0;
	struct node *three=0;
	struct node *four=0;

	one = malloc(sizeof(struct node));   // use of malloc function to allocate the 
	two = malloc(sizeof(struct node));    // memory 
	three = malloc(sizeof(struct node));
	four = malloc(sizeof(struct node));


	printf("\n Enter four integer to create node first");
	  
  // print the massage of user whate type of data have to entered  and why get the 
  //information from user and print the limked list   
       
        printf("\n value of node1 no 1: ");
	fflush(stdout);      
	scanf("\n%d",&one->data);

	printf("\n value of node1 no 2:");
	fflush(stdout);
	scanf("\n%d",&two->data);

	printf("\n value of node1 no 3:");
	fflush(stdout);
	scanf("\n%d",&three->data);

	printf("\n value of node1 no 4:");
	fflush(stdout);
	scanf("\n%d",&four->data);

	one->next= two;
	two->next= three;
	three->next= four;
	four->next= NULL;

	head = one;
	
	struct node *head1;
       struct node *n2_1=0;
      struct node *n2_2=0;
      struct node *n2_3=0;
      struct node *n2_4=0;

    n2_1 = malloc(sizeof(struct node)); // use of malloc function to allocate the
    n2_2 = malloc(sizeof(struct node)); // memory 
    n2_3 = malloc(sizeof(struct node));
    n2_4 = malloc(sizeof(struct node));

    printf("\n Enter four integer to create node second");
   
  // print the massage of user whate type of data have to entered  and why get the 
  //information from user and print the limked list   

   printf("\n value of node1 no 1: "); // declare a struct type pointer to create node 
                                       //  and final create a link list of data
    fflush(stdout);
    scanf("\n%d",&n2_1 ->data);

    printf("\n value of node1 no 2:");
   fflush(stdout);
   scanf("\n%d",&n2_2->data);
{
   printf("\n value of node1 no 3:");
  fflush(stdout);
  scanf("\n%d",&n2_3->data);

  printf("\n value of node1 no 4:");
  fflush(stdout);
  scanf("\n%d",&n2_4->data);

  n2_1->next= n2_2;
  n2_2->next= n2_3;
  n2_3->next= n2_4;
  n2_4->next= NULL;

 head1 = n2_1;

 printf("\n first node Linked List\n");
 printf("\n");
 printlinkedlist(head );
 printf("\n");
		
 printf("\n second node Linked List\n");
 printf("\n");
 printlinkedlist(head1 );

		
 printf("\n");
 intersection(head, head1);   // call function due to perform intersection operation
 printf("\n");
 printf("\nIntersection Linked List\n");  
                                      // print the intersection link list sms to 
                                     //know the user whate type of list have to printed
 

 printf("\n");
 printf("\n");
 printlinkedlist(inter );   // call the printlinkred list function and print the list of 
                             // intyersection 

 findunion(head, head1);     // caling of findunion function to perform union operation
  printf("\n");
  printf("\n union Linked List\n");
  printlinkedlist(union_list);  // call the printlinkred list function and print the 
                                //list of intyersection 

 return 0;

}

   

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.