Challenge

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

1.

Here the main objective of the given project is to do the mathematical set operation.A set operation can be of different types.In the current project we are supposed to do the union and intersection of the list created as a linked list. Therefore we are creating a structure which has a collection of different data.At first we have to create two lists using the reference address.The main concept of linked list is self referential structure.

The code has been developed and enclosed as the word document Proj1_Set.The explanation is as under.

I.

In order to generate a linked list using two given lists we have used three header files for initialization purpose and these are 'stdbool.h','stdio.h' & 'stdlib.h'.

II.

Then we have made a structure for our usable node.

III.

Next function declaration was carried out.

IV.

Then getunion function is used to perform the union operation.

V.

Thereafter insertion of all elements of the first list was done.For this task 'push' function has been used.

VI.

After the above step the same procedure was followed for unique or uncommon elements of second list.

VII.

Next getintersection function is used to perform the intersection operation.

VIII.

A 'while' loop is used to find common elements in list 1 & list 2 using 'push' function.

IX.

After this 'malloc()' is used to dynamically allocate a single block of memory (it is available in the header stdlib.h). 'sizeof()' is used to determine size in bytes of each node and sent as a parameter to malloc().

X.

Finally the result was dispalyed using 'printf' command.We have created a temporary list with the head as NULL and print data and use the next address stored in the pointer variable pointing to the structure.

The code developed was tested using onlinegdb and the test result is enclosed as the image file Proj1_Set.PNG.We have four elements in the first list and five elements in the second list.Out of these two elements are common to both lists.In the Intersection list the common elements are being displayed.In the Union altogether seven elements are being displayed.

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.