#include<stdio.h>
#include<malloc.h>
struct list
{
int data;
struct list*next;
};
struct list *head3=NULL,*head4=NULL, *head1=NULL,*head2=NULL,*head5=NULL;
struct list* push(struct list* head,int data)
{
struct list *new=(struct node*)malloc(sizeof(struct list));
new->data=data;
new->next=NULL;
if(head==NULL)
{
head=new;
}
else
{
new->next=head;
head=new;
}
return head;
}
void print(struct list*head)
{
if(head==NULL)
printf("empty");
else
{
while(head)
{
printf("%d",head->data);
head=head->next;
}
}
}
struct list* rev(struct list*head)
{
struct list *temp=NULL,*prev=NULL;
if(head==NULL)
return 0;
else
{
while(head)
{
temp=head->next;
head->next=prev;
prev=head;
head=temp;
}
}
return prev;
}
struct list *sub(struct list*up,struct list*lo)
{
if(head1==NULL||head2==NULL)
return 0;
else
{
printf("\n");
head1=rev(head1);
printf("\n");
print(head1);
head2=rev(head2);
printf("\n");
print(head2);
printf("\n");
while(head2!=NULL)
{
if(head1->data>=head2->data)
{
head3=push(head3,(head1->data)-(head2->data));
}
else
{
head1->next->data=head1->next->data-1;
head1->data+=10;
head3=push(head3,(head1->data)-(head2->data));
}
head1=head1->next;
head2=head2->next;
}
head3=push(head3,head1->data);
printf("\n");
print(head3);
}
}
int main()
{
head1=push(head1,1);
head1=push(head1,3);
head1=push(head1,5);
head1=push(head1,4);
print(head1);
head2=push(head2,1);
head2=push(head2,4);
head2=push(head2,9);
printf("\n");
print(head2);
sub(head1,head2);
}