forked from R0HITKUMAR/webDevUsingGSheets.sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedListNoSub.c
More file actions
59 lines (57 loc) · 1.18 KB
/
linkedListNoSub.c
File metadata and controls
59 lines (57 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Find out the Subtraction of two given link list 125+85 =210 1->2->5 8->5
#include<stdio.h>
#include<math.h>
#include "linkedList.h"
void sub(struct node **list1,struct node **list2)
{
struct node *p,*q;
int c1=0,c2=0,temp;
float sub1=0,sub2=0;
p = (*list1);
q = (*list2);
while (p!=NULL)
{
sub1+=p->info *pow(10,c1);
c1+=1;
p = p->next;
}
while (q!=NULL)
{
sub2+=q->info *pow(10,c2);
c2+=1;
q = q->next;
}
if (sub1>sub2)
temp = sub1-sub2;
else
temp = sub1-sub2;
printf("%d",temp);
linkedListFormation(temp);
}
void linkedListFormation(int temp)
{
int n;
struct node *P;
P = NULL;
while (temp!=0)
{
n = temp%10;
temp = temp/10;
InsBeg(&P,n);
}
printf("\nSubtraction Linked List : ");
Traverse(&P);
}
void main()
{
struct node *START1,*START2;
START1=NULL;
START2=NULL;
InsBeg(&START1,1);
InsBeg(&START1,2);
InsBeg(&START1,5);
InsBeg(&START2,8);
InsBeg(&START2,5);
printf("Subtraction of Lists : ");
sub(&START1,&START2);
}