Challenge

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

GUIDED BY ABINAYA INBAMANI

1.LINKED LIST

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

typedef struct node//defining the structure
{
      int data;//creating the data type of the variable
      struct node *next;// creating self referential node
}
Node;//changing the structure name as node

static Node *head1,*head2,*head,*head_union,*head_intersection,*newnode,*tail,*res_union,*res_intersection;//declaring the different variable in structure type
/* Declaring diffferent function with the argumrnts*/

Node *insert_node(Node *head_ref,int n);
void display_list(Node *head_ref);


void display_list(Node *head_ref)//function used to dispaly the nodes data .
{
 if(head_ref == 0)
{
     printf(" List is empty.");
}
else
{
       tail = head_ref;//we are transfering address if the list to tail
while(tail != 0)
{
       printf("%d ", tail->data);// prints the data of current node
       tail = tail->next;// advances the position of current node
}
       tail = newnode;
}
}

Node *insert_node(Node *head_ref,int n)//function used create the new list
{
        printf("\nInserting Elements at the beginning...\n");
        newnode =(Node*) malloc(sizeof(Node));//allocating the memory to the nodes
        printf("Address of created newnode :%d\n",newnode);
        newnode->data = n;//assigning the value to node
        printf("Inserted value is :%d\n",newnode->data);
        newnode->next = head_ref;//address of the pervious address is transfered to the new node
        head_ref = newnode;//transfering the new address to the head ref for linking new node
return head_ref;
}


int main()
{

int first_list_nodes = 0,second_list_nodes = 0,first_list_items = 0,
second_list_items = 0;
int f;
printf("Enter the number of Nodes in first List:");
fflush(stdout);
scanf("%d",&first_list_nodes);// 4( 2 3 4 5)
printf("Enter %d the elements:",first_list_nodes);//getting the number of element in the lists
for( f = 0;f < first_list_nodes;f++)
{
fflush(stdout);
scanf("%d",&first_list_items);//getting the data in run time
head1 = insert_node(head1,first_list_items);//inserting the data in list
}
display_list(head1);//displating the head1 list
printf("\nEnter the number of Nodes in second List:");
fflush(stdout);
scanf("%d",&second_list_nodes);
printf("Enter %d the elements:",second_list_nodes);
for(f = 0;f < second_list_nodes;f++)
{
fflush(stdout);
scanf("%d",&second_list_items);//getting the data in run time
head2 = insert_node(head2,second_list_items);
}
display_list(head2);//displating the head1 list

}

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.