K L UNIVERSITY
FRESHMAN ENGINEERING DEPARTMENT
A Project Based Lab Report
On
Implementation of Linked List Applications
SUBMITTED BY
I.D NUMBER NAME
190030230 B.Naveen
190030265 Ch.Kalyan
190030437 E.Sai Supriya
190030494 G.S.S.Dhanush
UNDER THE ESTEEMED GUIDANCE OF
Mr. S. PRADEEP RAJ
ASSISTANT PROFESSOR
KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES
CERTIFICATE
This is to certify that the project based laboratory report entitled
“Implementation of Linked List Applications” submitted by Mr/Mrs. B.Naveen, Ch.Kalyan,
E.Sai Supriya G.S.S.DHANUSH bearing Regd. No. 190030230, 190030265, 190030437,
190030494 to the Department of Basic Engineering Sciences, KL University in partial
fulfillment of the requirements for the completion of a project in “Object Oriented
Programming” course in I B Tech II Semester, is a bonafide record of the work carried out by
him/her under my supervision during the academic year 2019-20.
PROJECT SUPERVISOR HEAD OF THE DEPARTMENT
Mr. S. PRADEEP RAJ Dr. D. HARITHA
ACKNOWLEDGEMENTS
It is great pleasure for me to express my gratitude to our honorable President Sri.
Koneru Satyanarayana, for giving the opportunity and platform with facilities in
accomplishing the project based laboratory report.
I express the sincere gratitude to our director Dr. A Jagadeesh for his administration
towards our academic growth.
I express sincere gratitude to our Coordinator and HOD-BES Dr. D. Haritha for her
leadership and constant motivation provided in successful completion of our academic
semester. I record it as my privilege to deeply thank for providing us the efficient faculty and
facilities to make our ideas into reality.
I express my sincere thanks to our project supervisor Mr. S. PRADEEP RAJ for
his/her novel association of ideas, encouragement, appreciation and intellectual zeal which
motivated us to venture this project successfully.
Finally, it is pleased to acknowledge the indebtedness to all those who devoted
themselves directly or indirectly to make this project report success.
Name: B.Naveen
Ch.Kalyan
E.Sai Supriya
G.S.S.Dhanush
Regd . No: 190030230
190030265
190030437
190030494
ABSTRACT
The main aim of this project is to implement one of the most important applications of linked
list. In this project we have to show the applications of linked list. That is
1. Polynomial Addition
2. Polynomial Subtraction
3. Polynomial Multiplication
4. Polynomial Derivation
By this project we can easily can solve the polynomial operations. It will become very easy
for doing the Addition, Subtraction, Multiplication and Derivation for the given expression.
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 Class Diagram 9
5 Implementation 10 - 19
6 Outputs/ ScreenShots 20
7 Conclusion 21
INTRODUCTION
Introduction to Linked Lists:- Linked List is a very commonly used linear data structure
which consists of group of nodes in a sequence. Each node holds its own data and the address
of the next node hence forming a chain like structure. Linked Lists are used to create trees
and graphs. By using the linked list we have created Node class to access exponential and
coefficient then we created Linked List (LL) class to access the values, make an polynomial
equation in terms of “x” and operations like Addition, Subtraction, Multiplication,
Differentiate the polynomial equations.
AIM
Advantages: We can easily calculate the polynomial operations using liked list
Disadvantages: There are no disadvantages
Future enhancements: By this we can speed up polynomial calculations
SYSTEM REQUIREMENTS
SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Java
Operating system: windows 7 (or) above
Software : ECLLIPSE.
HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
RAM : 2gb
Processor : i5 (or) above
CLASS DIAGRAM
IMPLEMENTATION
Node.java
public class Node
{
int exp;
float coeff;
Node next;
}
LL.java
import java.util.Scanner;
public class LL
{ Node head;
Scanner in = new Scanner(System.in);
public LL create(int p1)
{
LL poly = new LL();
String co,ex;
int exp;
float coeff;
for(int i=1 ;i <= p1;i++)
{
System.out. print("Enter coeff of term"+Integer.toString(i)+": ");
co = in. nextLine();
System.out. print("Enter exponent of term"+Integer.toString(i)+": ");
ex = in. nextLine();
coeff = Float.parseFloat(co);
exp = Integer.parseInt(ex);
poly.insert(coeff,exp);
}
return poly;
}
public Node returnhead()
{
return head;
}
public void insert(float coeff,int exp)
{
Node node = new Node();
node.exp = exp;
node.coeff = coeff;
node.next = null;
if(head == null)
{
head = node;
}
else
{
Node n = head;
while(n.next != null)
{
n = n.next;
}
n.next = node;
}
}
public void show()
{
Node tmp = head;
if(tmp == null)
System.out.println("Zero Polynomial");
else
{
while(tmp != null)
{
System.out.print("("+Float.toString(tmp.coeff)+")"+"x^"+Integer.toString(tmp.exp));
tmp = tmp.next;
if(tmp != null)
System.out.print(" + ");
else
{
System.out.println();
}
}
}
}
public void poly_add(Node poly1,Node poly2)
{
LL poly3 = new LL();
if(poly1 == null || poly2 == null)
{
System.out.println("One is zeropolynomial");
return;
}
while(poly1 != null && poly2 != null)
{
if(poly1.exp > poly2.exp )
{
poly3.insert(poly1.coeff,poly1.exp);
poly1 = poly1.next;
}
else
{
if(poly1.exp < poly2.exp)
{
poly3.insert(poly2.coeff,poly2.exp);
poly2 = poly2.next;
}
else
{
poly3.insert(poly1.coeff+poly2.coeff,poly1.exp);
poly2 = poly2.next;
poly1 = poly1.next;
}
}
}
while( poly1 != null)
{
poly3.insert(poly1.coeff,poly1.exp);
poly1 = poly1.next;
}
while( poly2 != null)
{
poly3.insert(poly2.coeff,poly2.exp);
poly2 = poly2.next;
}
System.out.println("The poly after addtion is:");
poly3.show();
}
public void poly_subs(Node poly1,Node poly2)
{
LL poly3 = new LL();
if(poly1 == null || poly2 == null)
{
System.out.println("One is zeropolynomial");
return;
}
while(poly1 != null && poly2 != null)
{
if(poly1.exp > poly2.exp )
{
poly3.insert(poly1.coeff,poly1.exp);
poly1 = poly1.next;
}
else
{
if(poly1.exp < poly2.exp)
{
poly3.insert(poly2.coeff,poly2.exp);
poly2 = poly2.next;
}
else
{
poly3.insert(poly1.coeff-poly2.coeff,poly1.exp);
poly2 = poly2.next;
poly1 = poly1.next;
}
}
}
while( poly1 != null)
{
poly3.insert(poly1.coeff,poly1.exp);
poly1 = poly1.next;
}
while( poly2 != null)
{
poly3.insert(poly2.coeff,poly2.exp);
poly2 = poly2.next;
}
System.out.println("The poly after substraction is:");
poly3.show();
}
public void insertformul(float coeff,int exp)
{
Node tmp = head,tmp1=null;
int flag = 0;
while(tmp != null)
{
if(tmp.exp == exp)
{
tmp.coeff +=coeff;
flag =1;
break;
}
tmp1 = tmp;
tmp = tmp.next;
}
if (flag ==0)
{
Node node = new Node();
node.exp = exp;
node.coeff = coeff;
node.next = null;
if(head == null)
{
head = node;
}
else
{
tmp1.next = node;
}
}
}
public void poly_mul(Node poly1,Node poly2)
{
LL poly3 = new LL();
Node temp = poly2;
if(poly1 == null || poly2 == null)
{
System.out.println("One is zeropolynomial");
return;
}
while(poly1 != null)
{
poly2 = temp;
while(poly2 != null)
{
poly3.insertformul(poly1.coeff *poly2.coeff,poly1.exp+poly2.exp);
poly2 = poly2.next;
}
poly1 = poly1.next;
}
System.out.println("The poly after multiplication is:");
poly3.show();
}
public void poly_derive(Node poly1,Node poly2)
{ LL poly31 =new LL();
LL poly32 = new LL();
if( poly1 == null || poly2 == null)
{
System.out.println("one is Zero polynoial");
return ;
}
while(poly1 != null)
{
poly31.insert(poly1.coeff * poly1.exp,poly1.exp - 1);
poly1 = poly1.next;
}
while(poly2 != null)
{
poly32.insert(poly2.coeff * poly2.exp,poly2.exp - 1);
poly2 = poly2.next;
}
System.out.println("First poly derivative:"");
poly31.show();
System.out.println("Second poly derivative:");
poly32.show();
}
}
Main.java
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
String s;
int p;
Scanner in = new Scanner(System.in);
LL poly1 = new LL();
LL poly2 = new LL();
LL poly3 = new LL();
System.out. println("Enter number of terms in polynomial one");
s = in. nextLine();
p = Integer.parseInt(s);
poly1 = poly1.create(p);
System.out. println("polynomial one:");
poly1.show();
System.out. println("Enter number of terms in polynomial two");
s = in. nextLine();
p = Integer.parseInt(s);
poly2=poly2.create(p);
System.out. println("polynomial two:");
poly2.show();
System.out.println("1.Addition:");
poly3.poly_add(poly1.head,poly2.head);
System.out.println("2.Substraction:");
poly3.poly_subs(poly1.head,poly2.head);
System.out.println("3.Multiplication:");
poly3.poly_mul(poly1.head,poly2.head);
System.out.println("4.Derivation:");
poly3.poly_derive(poly1.head,poly2.head);
}
}
OUTPUT
Screen Shots:
CONCLUSION
By this we can easily calculate the operations like Addition, Subtraction, Multiplication,
Differentation in polynomial using linked list.