Question: JAVA PROGRAM Please help with the following Data Structures assignment, as the instructions follow. The files used are included. Please help. Given the two java
JAVA PROGRAM
Please help with the following Data Structures assignment, as the instructions follow. The files used are included.
Please help.
Given the two java files aNode.java and aLinkedList.java each has a class that will be used to create a linked list.
What your job is... for the aLinkedList.java file in a separate document explain what each line/part of the code is doing. This needs to be done as if the person that is reading it has a little programming experience. It also needs to be done in a professional manor not as if you sending an email.
Also for each file you are to comment the code so it is more clear as to what each part is doing. In the appropriate places comment in the Java Doc format.
Once you have completed these tasks write a main driver that will test all methods of the aLinkedList class.
aNode.java
class aNode
{
protected String data;
protected aNode link;
public aNode()
{
link = null;
data = "";
}
public aNode(String d,aNode n)
{
data = d;
link = n;
}
public void setLink(aNode n)
{
link = n;
}
public void setData(String d)
{
data = d;
}
public aNode getLink()
{
return link;
}
public String getData()
{
return data;
}
}
aLinkedList.java
Pageof 2
ZOOM
class aLinkedList
{
protected aNode start;
protected aNode end ;
public int size ;
public aLinkedList()
{
start = null;
end = null;
size = 0;
}
public boolean isEmpty()
{
return start == null;
}
public int getSize()
{
return size;
}
public void insertAtStart(String val)
{
aNode nptr = new aNode(val, null);
size++ ;
if(start == null)
{
start = nptr;
end = start;
}
else
{
nptr.setLink(start);
start = nptr;
}
}
public void insertAtEnd(String val)
{
aNode nptr = new aNode(val,null);
size++ ;
if(start == null)
{
start = nptr;
end = start;
}
else
{
end.setLink(nptr);
end = nptr;
}
}
public void insertAtPos(String val , int pos)
{
aNode nptr = new aNode(val, null);
aNode ptr = start;
pos = pos - 1 ;
for (int i = 1; i < size; i++)
{
if (i == pos)
{
aNode tmp = ptr.getLink() ;
ptr.setLink(nptr);
nptr.setLink(tmp);
break;
}
ptr = ptr.getLink();
}
size++ ;
}
public void deleteAtPos(int pos)
{
if (pos == 1)
{
start = start.getLink();
size--;
return ;
}
if (pos == size)
{
aNode s = start;
aNode t = start;
while (s != end)
{
t = s;
s = s.getLink();
}
end = t;
end.setLink(null);
size --;
return;
}
aNode ptr = start;
pos = pos - 1 ;
for (int i = 1; i < size - 1; i++)
{
if (i == pos)
{
aNode tmp = ptr.getLink();
tmp = tmp.getLink();
ptr.setLink(tmp);
break;
}
ptr = ptr.getLink();
}
size-- ;
}
}
When you are done you will need to uploaded four (4) files:
Your document file
Your aNode.java file (that has been commented)
Your aLinkedList.java file (that has been commented)
Your driver.java file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
