Challenge

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

offfline batch

alex ruban

1)

// Online C compiler to run C program online
#include<stdio.h>
#include<stdlib.h>

struct node //node creation
{
int data;
struct node *next;
};
void printalex(struct node *a); //function prototype & function declaration
int main()

{

struct node *temp=NULL;
struct node *head; //node declaration
struct node *one = NULL;
struct node *two = NULL;
struct node *three = NULL;

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

printf("\n Enter one->data value ="); //Ask the value from user
scanf("%d",&one->data );
printf("\n Enter two->data value =");
scanf("%d",&two->data );
printf("\n Enter three->data value =");
scanf("%d",&three->data );

one->next = two; //connecting the nodes
two->next = three;
three->next = NULL; // initialization
head = one;

printalex(head); //caller function
printf("\n");

struct node *four = NULL;
four = malloc(sizeof(struct node));
printf("\n Enter four->data value =");
scanf("%d",&four->data );

//INSERTING NEW NODE
four->next = NULL;
three->next = four;
printalex(head);
printf("\n");

//DELETING NODE FOR USER CHOICE

temp=head;
head=two;
free(temp);
printalex(head);



}

void printalex(struct node *a) //Called function

{
while (a!=NULL)
{
printf("%d",a->data);
a=a->next;
}
}

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.