How to write a c program to create two singly linked list and perform differencer of two list and display it in C Programming Language ?
Solution:/*write a c program to create two singly linked list and perform
differences of two list and display it*/
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int data;
struct node *next;
}*start1=NULL,*start2=NULL,*q1,*q2,*temp1,*temp2;
int n1=0,n2=0,*p1,*p2,i,j;
void create();
void display();
void differ();
void main()
{
clrscr();
create ();
display();
differ();
getch();
}
void create()
{
char ch='y';
while(ch=='y'||ch=='Y')
{
temp1=malloc(sizeof(struct node));
printf("\nenter the number for first L.L:-");
scanf("%d",&temp1->data);
temp1->next=NULL;
n1++;
if(start1==NULL)
start1=temp1;
else
{
q1=start1;
while(q1->next!=NULL)
{
q1=q1->next;
}
q1->next=temp1;
}
printf("\ndo you want to continue(Y|N):-");
scanf("\n%s",&ch);
}
ch='y';
while(ch=='y'||ch=='Y')
{
temp2=malloc(sizeof(struct node));
printf("\nenter the number for second L.L:-");
scanf("%d",&temp2->data);
temp2->next=NULL;
n2++;
if(start2==NULL)
start2=temp2;
else
{
q2=start2;
while(q2->next!=NULL)
{
q2=q2->next;
}
q2->next=temp2;
}
printf("\ndo you want to continue(Y|N):-");
scanf("\n%s",&ch);
}
}
void display()
{
p1=(int *)malloc(n1*sizeof(int));
p2=(int *)malloc(n2*sizeof(int));
if(start1==NULL)
printf("\nlinked list is empty");
else
{
printf("\nelement in first linked list are:-\n");
q1=start1;
for(i=0;i<n1;i++)
{
if(q1!=NULL)
{
*(p1+i)=q1->data;
printf("%d\n",*(p1+i));
q1=q1->next;
}
}
}
if(start2==NULL)
printf("\nlinked list is empty");
else
{
printf("\nelement in second linked list are:-\n");
q2=start2;
for(i=0;i<n2;i++)
{
if(q2!=NULL)
{
*(p2+i)=q2->data;
printf("%d\n",*(p2+i));
q2=q2->next;
}
}
}
}
void differ()
{
printf("\ndifferences of two sets are:-\n");
for(i=0;i<n1;i++)
{
for(j=0;j<n2;j++)
{
if(*(p1+i)==*(p2+j))
break;
}
if(j==n2)
printf("%d\n",*(p1+i));
}
}
Output:
/*
enter the number for first L.L:-4
do you want to continue(Y|N):-y
enter the number for first L.L:-8
do you want to continue(Y|N):-y
enter the number for first L.L:-1
do you want to continue(Y|N):-y
enter the number for first L.L:-6
do you want to continue(Y|N):-n
enter the number for second L.L:-4
do you want to continue(Y|N):-y
enter the number for second L.L:-1
do you want to continue(Y|N):-n
element in first linked list are:-
4
8
1
6
element in second linked list are:-
4
1
differences of two sets are:-
8
6
*/
Learn More :
Display
- DISPLAY SOURCE CODE AS OUTPUT IN C PROGRAM
- Sort Three Numbers - program reads in three Integers and displays them in ascending order.
- C Program To Display The Number In A Specific Formats
- C Program that Display a IBM Logo
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- LED ON OFF For One Sec/Count and Display on the Attached Serial Monitor
- Pre Order, Post order, In order Implement Binary Tree using linked list
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C Program to accept n numbers & store all prime numbers in an array & display this result
- C program to display the transpose of given 3 X 3 matrix
- C Program to accept a string from user, delete all vowels from that string & display the result
- C Program To Create Two Singly Linked List and Perform Following Operation
- C Program to Create, Display, Insert and Deletion of Queue Elements
- Creation and Display of Elements in Both Forward and Reverse Direction in a Doubly Linked List
- C Program to Display a real time clock (HH:MM:SS) on the LCD
- Program to Display Pie Chart Accepting User Input C Program
- Linked List For Getting Employee Details, Display and Search For Salary C Program
- Menu driven program in the creation,display,search, insertion and deletion of a node in the linked list
- Program to display the following pattern in C
- Display the Following Pattern * ** *** **** ***** C Program
Two
- Write a c program to find out H.C.F. of two numbers.
- Write a C program to find maximum or equal between two numbers ?
- ADDITION OF TWO MATRICES USING C PROGRAM
- C Program To Find Product Of Two No Using MACRO
- C Program To Swap Two Numbers Without Using Third Variable
- C Program Concatenating Two Strings Into A Third System
- C Program to concatenate two strings without using string functions
- C Program to Interchanging Two Numbers
- C Program produsul scalar a doi vectori .
- C Program The dot product of two vectors
- C Program to two timing functions to measure process time
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to swap the values of two variables by using call by reference
- Find the union and intersection of two sets of integer store it in two array C Program
- Menu driven program in C to Calculate Length, Copy into Another Compare Concatenate of Two String
- C Program To Multiply Two Polynomials
- C Program to Input Student Details into a File For Two Subjects
- Adding two polynomial functions C Program Using Structure
- Program to Add Two Polynomials Using Linked List C Program
- Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program
- Input Two Numbers and Print Greater Number C Program
Data Structure
- C program to remove last of singly linked list and insert it at beginning of list
- C Program To Read A Parenthesised Infix Expression From The User And Check Whether It Is Well Parenthesised Or Not
- C Program To Remove Last Of Singly Linked List And Insert It At Beginning of List
- C Program To Remove First Node Of Singly Linked List And Insert It At End Of The List
- C Program To Read The Adjecancy Matrix of Directed Graph And Convert It Into Adjecancy List
- C Program To Create Two Singly Linked List and Perform Following Operation
- C Program - Hash Table to store information about a student
- GJK C Program Example-1
- Adding two polynomial functions C Program Using Structure
- Program to Add Two Polynomials Using Linked List C Program
- Adding Two Polynomial Functions in C Program
Perform
Singly Linked List
Difference
Create
- How To Write a C program that creates customers' bills for a carpet company when the following is given ?
- C Program to Create VIRUS
- Creates new main.c with empty main boilerplate template
- C Program to create a solution to the Towers of Hanoi game
- C Program to Create a copy of an image
- Ardunio: Create a crystal ball to tell you the future C Program
- C Program to Creating pico device
- Add x and y coordinates to create a new struct in C Program
- C program allocates new nodes and creates a four element list with fixed values
- C Program To Create Two Singly Linked List and Perform Following Operation
- C Program Implement Binary Search Tree And Its Traversals
- C Program to Create, Display, Insert and Deletion of Queue Elements
- Creation and Display of Elements in Both Forward and Reverse Direction in a Doubly Linked List
- Calculator Using IF-ELSE in C Program