Académique Documents
Professionnel Documents
Culture Documents
On
SUBMITTED BY:
I.D NUMBER NAME
180031212 K.Hemanth
180031262 G.Tirumala
T.Rajesh Kumar
ASSST.PROF
KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
2
CERTIFICATE
ACKNOWLEDGEMENTS
I express the sincere gratitude to our principal ProfDr. N.Venkataram for his
administration towards our academic growth.
ABSTRACT
This Project is aimed to developing an Implementation of linked list applications. In
this project we have to develop the polynomial operations like addition, subtraction,
multiplication, differentiation, which are complex to do on a paper. so we have to perform
the above operations by using linked list concept to save the time of the user.
In order to perform the above operations we need to know about the concept of
linked list like how to create a node and how to allocate memory for a created node. We
need to know about the functions concept how to create a function, calling function, called
function and the concept of recursion. By using the above concepts we can implement the
polynomial operations like addition, subtraction, multiplication, differentiation.
1) Make a polynomial abstract datatype using struct which basically implements a linked
list.
2) We write different functions for creating a polynomial function, adding, subtraction,
multiplication, differentiation and showing a polynomial expression.
3) Finally we write the main function as many pair of polynomials the user wants.
5
INDEX
S.NO TITLE PAGE NO
1 Introduction 6
2 Aim of the Project 7
2.1 Advantages & Disadvantages 7
2.2 Future Implementation 7
3 Software & Hardware Details 8
4 Data Flow Diagram 9-10
5 Implementation 12-16
6 Algorithm 11
7 Integration and System Testing 17-18
8 Conclusion 20
INTRODUCTION 6
The main aim of this project is to implement one of the most important applications of
linked list such as polynomial operations such as addition, subtraction, multiplication and
derivation. To perform these operations each polynomial needs to represent in one linked list
and each node in the list contains three parts to store coefficient, exponent and link to next
term of polynomial respectively. There are four modules in in this project
polynomial Addition
polynomial subtraction
polynomial multiplication
polynomial derivation
Requirements: To implement this project student should have knowledge on
creating using linked lists
pointers, self-referential structures
polynomial operations
AIM 7
The Aim of the project is to execute the polynomial operations like addition, Subtraction,,
Multiplications, Differentiation etc using the concept of linked lists reducing the time
complexity to the user.
Advantages:-
Disadvantages:-
1. Length of the code is too long.
2. User should be careful while giving inputs
3. Occupies more memory and space in computer memory.
Future enhancements:-
1. The polynomial operations can be easily implemented by using the concept of
arrays rather than linked list.
2. Not only by linked lists we can also implement these operations by using
linear data structures like arrays, double linked lists etc .
8
SYSTEM REQUIREMENTS
SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Java 2 Runtime environment
Database :MySQL Server
Web Server :Tomato 7
Software Development Kit :JSP(Java server Pages)
Database JDBC Driver :MySQL Jconnector
Operating system:Windows Xp or later.
HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
RAM : 128 MB
Hard Disk : 20GB
9
DATA FLOW DIAGRAM
START
PRINT MENU
YES IF OP==1 NO
YES IF OP==2
ADDITION
PERFORMS
ADDITION NO
OPERATION
BETWEEN TWO
POLYNOMIALS
SUBTRACTION
PERFORMS 10
SUBTRACTION
BETWEEN TWO
POLYNOMIALS YES
IF OP==3
NO
MULTIPLICATION
IF OP==4
PERFORMS YES
MULTIPLICATION
OPERATION
BETWEEN TWO
POLYNOMIALS NO
DIFFERENTIATION
IF OP==5
PERFORMS
DIFFERENTIATION
BETWEEN TWO
POLYNOMIALS
STOP
ALGORITHM
11
1) Start
2) Create a structure which consists of integer part of coefficient, integer part of power, and
a self referential structure with in it.
3) Create 3 variables poly1-> to store co-efficients and powers of first polynomial, poly2->
to store co-efficients and powers of second polynomial, poly-> to store resultant co-efficient
and resultant power of resultant polynomial after performing the polynomial operation.
4) create a create function and allocate memory for poly1, poly2, poly
8) Scan the co-efficients and powers of poly1,poly2 and call the create function and memory
will be allocated to poly1,poly2.
9) Now if you want to perform addition operation among polynomials Call the addition
function and output will be displayed.
10) Now if you want to perform subtraction operation among polynomials Call the
subtraction function and output will be displayed
11) Now if you want to perform addition operation among polynomials Call the
multiplication function and output will be displayed
12) Now if you want to perform Differentiation operation among polynomials Call the
Differentiation function and output will be displayed
13)stop
IMPLEMENTATION 12
#include<stdio.h>
#include<malloc.h>
struct link{
int coeff;
int pow;
struct link *next;
};
struct link *poly1=NULL,*poly2=NULL,*poly=NULL;
void create(struct link *node)
{
char ch;
do
{
printf("\n\nenter coeff:");
scanf("%d",&node->coeff);
printf("\nenter power:");
scanf("%d",&node->pow);
node->next=(struct link*)malloc(sizeof(struct link));
node=node->next;
node->next=NULL;
printf("\ncontinue(y/n):");
}
while(ch=='y' || ch=='Y');
}
void show(struct link *node)
{
while(node->next!=NULL)
{
printf("%dx^%d",node->coeff,node->pow);
node=node->next;
if(node->next!=NULL)
printf(" + ");
}
}
void polyadd(struct link *poly1,struct link *poly2,struct link *poly)
{
while(poly1->next && poly2->next)
{
if(poly1->pow>poly2->pow)
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff;
poly1=poly1->next;
}
else if(poly1->pow<poly2->pow)
{ 13
poly->pow=poly2->pow;
poly->coeff=poly2->coeff;
poly2=poly2->next;
}
else
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff+poly2->coeff;
poly1=poly1->next;
poly2=poly2->next;
}
poly->next=(struct link *)malloc(sizeof(struct link));
poly=poly->next;
poly->next=NULL;
}
while(poly1->next || poly2->next)
{
if(poly1->next)
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff;
poly1=poly1->next;
}
if(poly2->next)
{
poly->pow=poly2->pow;
poly->coeff=poly2->coeff;
poly2=poly2->next;
}
poly->next=(struct link *)malloc(sizeof(struct link));
poly=poly->next;
poly->next=NULL;
}
void polymul(struct link *n1, struct link *n2, struct link *n)
{
struct link * n2beg=n2;
while (n1)
{
struct link * temp=(struct link *)malloc(sizeof(struct link));
temp->next=NULL;
n2=n2beg;
while (n2)
{
temp->coeff = n1->coeff * n2->coeff;
n2 = n2->next; 15
temp->next=(struct link *)malloc(sizeof(struct link));
temp=temp->next;
temp->next=NULL;
polyadd(temp,n,n);
n1 = n1->next;
free(temp);
}
}
while(p1->next!=NULL)
{
p2->coeff=p1->coeff*p1->pow;
p2->pow=p1->pow-1;
p2->next=NULL;
p2->next=(struct link *)malloc(sizeof(struct link));
p2=p2->next;
p2->next=NULL;
p1=p1->next;
}
}
int main()
{
int op;
char ch;
do{
poly1=(struct link *)malloc(sizeof(struct link));
poly2=(struct link *)malloc(sizeof(struct link));
poly=(struct link *)malloc(sizeof(struct link));
printf("\n\nWhat do you want to
do?\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Differentiation\n0.exit\nEnter your
choice:");
scanf("%d",&op);
switch(op)
{
case 1:
printf("\n\nenter 1st polynomial:");
create(poly1);
printf("\n\nenter 2nd polynomial:");
create(poly2);
printf("\n1st Polynomial:\t");
show(poly1);
printf("\n2nd Polynomial:\t");
show(poly2); 16
polyadd(poly1,poly2,poly);
printf("\nAdded polynomial:\t");
show(poly);
break;
case 2:
printf("\n\nenter 1st polynomial:\t");
create(poly1);
printf("\n\nenter 2nd polynomial:\t");
create(poly2);
printf("\n\n1st Polynomial:\t");
show(poly1);
printf("\n\n2nd Polynomial:\t");
show(poly2);
polysub(poly1,poly2,poly);
printf("\n\nSubtracted polynomial:\t");
show(poly);
break;
case 3:
printf("\n\nenter 1st polynomial:");
create(poly1);
printf("\n\nenter 2nd polynomial:");
create(poly2);
printf("\n\n1st Polynomial:\t");
show(poly1);
printf("\n\n2nd Polynomial:\t");
show(poly2);
polymul(poly1,poly2,poly);
printf("\n\nMultiplied polynomial:\t");
show(poly);
break;
case 4:
printf("\n\nenter polynomial:");
create(poly1);
printf("\n\nPolynomial:\t");
show(poly1);
diff(poly1,poly2);
printf("\n\nDifferentiated Polynomial:\t");
show(poly2);
break;
}
OUTPUTS
Screen Shots:
18
CONCLUSION 19
There are pretty good real examples to show the usage and importance of linkedlist.
Consider the history section of web browsers, where it creates a linked list of web-
pages visited, so that when you check history (traversal of a list) or press back
button, the previous node's data is fetched.
One common sighted example is low level memory management (i.e. the heap as
managed by malloc in C or new in Java, etc) is often implemented as a linked list,
with each node representing a used or available (free) block of memory. These
blocks may be of any size, change size (combine and split), be freed or assigned in
any order, and reordered. A linked list means you can keep track of all of these
"nodes" and manipulate them fairly easily.
Also, Hashtables that use chaining to resolve hash collisions typically have one
linked list per bucket for the elements in that bucket.
A simple real life example is a Train, here each coach is connected to its previous
and next coach (Except first and last). In terms of programming consider coach body
as node value and connectors as links to previous and next nodes.
Our brain is also a good example of linked list. In the initial stages of learning
something by heart, the natural process is to link one item to next. It's a subconscious
act. Also, when we forget something and try to remember, than our brain follows
association and tries to link one memory with another and so on and we
finally recall the lost memory.
E.g. Consider the thinking process when you placed your bike key somewhere and
couldn't remember.
Another real life example could a be queue/line of persons standing for food in mess,
insertion is done at one end and deletion at other. And these operations happen
frequent. dynamic queues / stacks are efficiently implemented using linkedlists.