Challenge

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

Solution:

Overview of the project:

The main objective of these project is we can perform Mathematical Set Operation Using C program. For these Projecct we can create two list of elements and we can find union and Intersection elements in two list. Here for creating two list of elements we can use Singly Linked list. Linked List is a Type of Linear Data Structure.

Creation of Two lists:

Our First step is to get a two list of data elements from user, for these first we create a Linked list using structure .Generally structure is Collection of diffrent data types for these purpose it contains two parts one is data part and another one is Pointer. data is actual elments from user and pointer contains address of next data element.Here we using Dynamic Memory allocation concept. first we get a number of elements user wants in each list and also get a data from user and store in Linked list format.

Find union and Intersection in two lists:

After getting data from user next step is find union and Intersection of two lists. Here we can create two list one is Union list and Intersection list. for finding Union first we can copy any one of the list in Union list. after that we can compare the list one and list two using Compare function the data not present in copied list copy the data elements to Union list.

For finding Intersection elements compare the two lists using compare function and copy the data which is same in both lists to Intersection list.

Algorithm:

  1. Start
  2. Define a structure for linked list list1,list2,Union List,Intersection list.
  3. Declare a Variable k,l,temp for number of nodes and data.
  4. Read the Variable from user for number of nodes for lists
  5. Create a for loop that runs number i<node, and for every iteration it calls a function getdata() for inserting a data in list.
  6. Use Malloc function for dynamic memory allocation of nodes.
  7. After inserting all data in list using display() function display the list one and list two data.
  8. Call the Getunion() function to get the union and pass the list1 and list2 head as argument.
  9. In that function create a temp pointer. and copy the list 1 head in temp using the copy the list1 data in Union list using same getdata() Function.
  10. And Call the Compare() function that comapre the List1 and List2 that will return 0 if not same and we call the getdata() function to that data in Unionlist.
  11. For intersection list call the compare() function if list one and list two data is same it will return a 1 if it is return 1 that time we call the getdata() function to insert the data intersection list.
  12. Finally display the union and Intersection list using display() function.
  13. End.

Answer:

Upload the coding in .C file and also upload the Screenshot of the Output.

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.