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 //offline embd karthick raj k
#include<stdio.h>
#include<stdlib.h>

struct node
{
int val;
struct node *nxt;
};
void printOp(struct node *d) // to print the linked list
{
while(d != NULL)
{
printf("%d", d->val );
d = d->nxt;
}
}
int main()
{
struct node *temp = NULL; // initializing nodes
struct node *head = NULL;
struct node *one = NULL;
struct node *two = NULL;
struct node *three = NULL;

one = malloc(sizeof(struct node)); //allocating memory
two = malloc(sizeof(struct node));
three = malloc(sizeof(struct node));

printf(" enter the first val = "); // to initalize node values from user
fflush(stdout);
scanf("%d",&one->val);
printf(" enter the second val = ");
fflush(stdout);
scanf("%d",&two->val);
printf(" enter the third val = ");
fflush(stdout);
scanf("%d",&three->val);

one->nxt = two; // to connect nodes 1,2,3
two->nxt = three;
three->nxt = NULL;

head = one; //to print head from begining
printOp(head);

struct node *four = NULL; // to add next node
four = malloc(sizeof(struct node)); // size for 4th value

printf("\nenter the fourth val = " );// to read 4th value
fflush(stdout);
scanf("%d",&four->val);

three->nxt = four; // to add 4th node to existing node
four->nxt = NULL;

printOp(head); // will print head including fourth
printf("\n");

temp=two; // to remove the second node( middle node)
one->nxt=three;
free(temp);
printOp(head); //will print head after removing 2nd node

}

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.