Exp:1 Implementation of Singly 20/12/'18 Linked List Operations
Exp:1 Implementation of Singly 20/12/'18 Linked List Operations
SOURCE CODE:
#include<stdio.h>
#include<stdlib.h>
struct node
int ele;
};
void create()
head->ele=0;
head->link=NULL;
void insert()
int i,ele,n;
p=head;
for(i=0;i<n;i++)
scanf("%d",&ele);
x->ele=ele;
x->link=NULL;
if(head->link==NULL)
head->link=x;
else
while(p->link!=NULL)
p=p->link;
p->link=x;
void deletes(int x)
p=head->link;
while((p->ele)!=x)
q=p;
p=p->link;
q->link=p->link;
free(p);
void display()
p=head->link;
while(p!=NULL)
printf("\n%d",p->ele);
p=p->link;
void main()
create();
insert();
deletes(5);
display();
RESULT:
Thus the above code has been verified successfully.
EXP :2 IMPLEMENTATION OF POLYNOMIAL ADDITON
20/12/’18 USING CIRCULAR LINKED LIST
AIM:
To implement polynomial addition using circular linked list.
SOURCE CODE:
#include<stdio.h>
#include<stdlib.h>
struct node
int coeff,exp;
};
void create()
head1->coeff=0;
head1->exp=-1;
head1->link=head1;
head2->coeff=0;
head2->exp=-1;
head2->link=head2;
head3->exp=-1;
head3->link=head3;
int ex,co,i,n;
scanf("%d",&n);
p=h;
for(i=0;i<n;i++)
printf("\nCo-efficient : ");
scanf("%d",&co);
printf("\nExponent : ");
scanf("%d",&ex);
x->coeff=co;
x->exp=ex;
x->link=h;
p->link=x;
p=x;
}
}
void display()
p=head3->link;
while(p->exp!=-1)
p=p->link;
s->coeff=c;
s->exp=e;
s->link=head3;
d->link=s;
d=s;
display();
{
struct node *p;
d=head3->link;
p=h1->link;
q=h2->link;
while((p->exp!=-1)&&(q->exp!=-1))
int x;
if((p->exp)==(q->exp))
x=p->coeff+q->coeff;
if(x!=0)
attach(x,p->exp,d);
p=p->link;
q=q->link;
else if((p->exp)>(q->exp))
attach(p->coeff,p->exp,d);
p=p->link;
}
else
attach(q->coeff,q->exp,d);
q=q->link;
while(p->exp!=-1)
attach(p->coeff,p->exp,d);
p=p->link;
while(q->exp!=-1)
attach(q->coeff,q->exp,d);
q=q->link;
void main()
create();
printf("\nPOLYNOMIAL 1\n");
insert(head1);
printf("\nPOLYNOMIAL 2\n");
insert(head2);
printf("\nRESULT\n");
add(head1,head2);
RESULT:
Thus the above code has been verified successfully.