Challenge

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

project1 i have to sumitted the programme and outputalso

project 1:


#include<stdio.h>
#include<stdlib.h>

struct list
{
	int P,Q;
	struct list *next;
};

int main()
{
	   struct list *A1,*A2,*A3,*B1,*B2,*B3;


	    	A1 = malloc(sizeof(struct list));
	    	A2 = malloc(sizeof(struct list));
	    	A3 = malloc(sizeof(struct list));

	    	A1 -> P = 1;
	    	A2 -> P = 2;
	    	A3 -> P = 3;

	    	A1->next = A2;
	    	A2->next = A3;
	    	A3->next = NULL;


	    {
	    	B1 = malloc(sizeof(struct list));
	    	B2 = malloc(sizeof(struct list));
	    	B3 = malloc(sizeof(struct list));

	    	B1 ->Q = 1;
	    	B2 ->Q = 2;
	    	B3 ->Q = 6;

	    	B1-> next = B2;
	    	B2-> next = B3;
	    	B3-> next = NULL;
	    }
	    //List 1 printing
	    printf("____list____\n");
	    fflush(stdout);
	    printf("%d\n",A1->P);
	    fflush(stdout);
	    printf("%d\n",A2->P);
	    fflush(stdout);
	    printf("%d\n",A3->P);
	    fflush(stdout);


	    //List 2 printing
	    printf("__list2___\n");
	    fflush(stdout);
	    printf("%d\n",B1->Q);
	    fflush(stdout);
	    printf("%d\n",B2->Q);
	    fflush(stdout);
	    printf("%d\n",B3->Q);
	    fflush(stdout);

	    //Adding link to list1 and printing
	    struct list *A4,*A5;
	    A4 = malloc(sizeof(struct list));
	    A5 = malloc(sizeof(struct list));

	    A4 -> P = 4;
	    A5 -> P = 5;

	    A1-> next = A2;
	    A2-> next = A3;
	    A3-> next = A4;
	    A4-> next = A5;
	    A5-> next = NULL;

	    printf("____Adding link to list1___\n");   //adding link to list1
	    fflush(stdout);
	    struct list *temp1 = A1;
	    while(temp1!=NULL)
	    {
	    	printf("%d\n",temp1->P);
	    	fflush(stdout);
	    	temp1 = temp1->next;
	    }

	    //Adding link to link 2 and printing
	    struct list *B4,*B5;
	    B4 = malloc(sizeof(struct list));
	    B5 = malloc(sizeof(struct list));

	    B4 ->Q = 7;
	    B5 ->Q = 8;

	    B1-> next = B2;
	    B2-> next = B3;
	    B3-> next = B4;
	    B4-> next = B5;
	    B5-> next = NULL;

	    printf("____Adding link to list2___\n");
	    fflush(stdout);
	    struct list *temp2 = B1;
	    while(temp2!=NULL)
	    {
	    	printf("%d\n",temp2->Q);
	    	fflush(stdout);
	    	temp2 = temp2->next;
	    }
	    printf("_______set operation of union_____\n");
	    fflush(stdout);

	    //set operation of union

	    if(A1->P == B1->Q)
	    {
	    	printf("%d\n",A1->P);
	    	fflush(stdout);
	    }
	    else
	    {
	    	printf("%d\n",A1->P);
	    	fflush(stdout);
	    	printf("%d\n",B1->Q);
	    	fflush(stdout);
	    }

	    //condition apply
	    if(A2->P == B2->Q)
	    {
	    	printf("%d\n",A2->P);
	    	fflush(stdout);
	    }
	    else
	    {
	    	printf("%d\n",A2->P);
	    	fflush(stdout);
	    	printf("%d\n",B2->Q);
	    	fflush(stdout);
	    }
	    if(A3->P == B3->Q)             //As check
	    {
	    	printf("%d\n",A3->P);
	        fflush(stdout);
	    }
	    else
	    {
	    	printf("%d\n",A3->P);
	        fflush(stdout);
	        printf("%d\n",B3->Q);
	        fflush(stdout);
	    }
	    if(A4->P == B4->Q)             //As check
	    {
	      printf("%d\n",A4->P);
	       fflush(stdout);
	    }
	    else
	    {
	    	printf("%d\n",A4->P);
	        fflush(stdout);
	        printf("%d\n",B4->Q);
	        fflush(stdout);
	    }
	    if(A5->P == B5->Q)               //As check
	    {
	    	printf("%d\n",A4->P);
	        fflush(stdout);
	    }
	    else                         //A5 else check
	    {
	    	printf("%d\n",A5->P);
	        fflush(stdout);
	        printf("%d\n",B5->Q);
	    	fflush(stdout);
	    }
	    printf("________set operation of intersection_______\n");
	    fflush(stdout);

	    //set operation of intersection
	      struct list *temp3 = A1;
	      struct list *temp4 = B1;
	      while(temp3!=NULL && temp4!=NULL)
	      {
	    	  if(temp3->P == temp4->Q)
	    	  {
	    		  printf("%d\n",temp3->P);
	    		  fflush(stdout);
	    		  temp3 = temp3->next;
	    		  temp4 = temp4->next;
	    	  }
	      }

}



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.

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.