Challenge

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

//******** PROJECT-1********

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

struct node
{
  int data;
  struct node *next;
} *LLOne, *LLTwo, *unionofLL, *intersectionofLL;


  void insert (struct node **head, int num)//creating function for insert node
{
  /* Create a new Linked List node */
  struct node *newNode = (struct node *) malloc (sizeof (struct node));
  newNode->data = num;
  newNode->next = *head;
  *head = newNode;
}

// comparing an element

 int compare(struct node *head, int num)
{
  while (head != NULL)
    {
      if (head->data == num)
	{
	  return 1;
	}
      head = head->next;
    }
  return 0;
}


struct node * findunion (struct node *LLOne, struct node *LLTwo) // function for find union
{
  unionofLL = NULL;
  // Add all nodes of first Linked List to unionLL
  struct node *temp = LLOne;
  while (temp != NULL)
    {
      insert (&unionofLL, temp->data);
      temp = temp->next;
    }
  // Insert those nodes of LLTwo which is not present in LLOne
  while (LLTwo != NULL)
    {
      if (!compare (LLOne, LLTwo->data))
	{
	  insert (&unionofLL, LLTwo->data);
	}
      LLTwo = LLTwo->next;
    }
  return unionofLL;
}


struct node * intersection (struct node *LLOne, struct node *LLTwo)
{
  intersectionofLL = NULL;
  while (LLOne != NULL)
    {
      if (compare(LLTwo, LLOne->data))
	{
	  insert (&intersectionofLL, LLOne->data);
	}
      LLOne = LLOne->next;
    }
  return intersectionofLL;
}


  void display(struct node *nodePtr)
{
  while (nodePtr != NULL)
    {
      printf ("%d", nodePtr->data);
      fflush(stdout);
      nodePtr = nodePtr->next;
      if (nodePtr != NULL)
	  printf ("-");
      fflush(stdout);
    }
}


int main ()
{
  int i, LLOneCount, LLTwoCount, temp;

  printf ("Enter number of nodes in first Linked List\n");
  fflush(stdout);
  scanf ("%d", &LLOneCount);
  printf ("Enter %d data\n", LLOneCount);
  fflush(stdout);
  for (i = 0; i < LLOneCount; i++)
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.