Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class LinkedList { private Node head; private Node tail; / / About method public String About ( ) { return This LinkedList class was
public class LinkedList
private Node head;
private Node tail;
About method
public String About
return "This LinkedList class was implemented by Gabriel";
AddHead method
public void AddHeadString value
Node newNode new Nodevalue;
newNode.next head;
head newNode;
if tail null
tail head;
AddTail method
public void AddTailString value
Node newNode new Nodevalue;
if tail null
head tail newNode;
else
tail.next newNode;
tail newNode;
RemoveHead method
public String RemoveHead
if head null
return ;
String value head.value;
head head.next;
if head null
tail null;
return value;
RemoveTail method
public String RemoveTail
if head null
return ;
if head tail
String value head.value;
head tail null;
return value;
Node current head;
while currentnext tail
current current.next;
String value tail.value;
tail current;
tail.next null;
return value;
IsEmpty method
public boolean IsEmpty
return head null;
ToString method
public String ToString
if head null
return ;
StringBuilder sb new StringBuilder;
Node current head;
while current null
sbappendcurrentvalue;
if currentnext null
sbappend;
current current.next;
return sbtoString;
ToStringReverse method
public String ToStringReverse
if head null
return ;
StringBuilder sb new StringBuilder;
Node current tail;
while current null
sbappendcurrentvalue;
if current head
sbappend;
current current.prev;
return sbtoString;
Node class
private class Node
private String value;
private Node next;
private Node prev; for ToStringReverse
public NodeString value
this.value value;
In java programming, can you add a code in main class on how to read a file under LinkedList programming, and please do not put it inside the LinkedList class. Part : Testing
A number of test files will be provided to you for testing your code. The format is designed to be easy to read in multiple
programming languages. You need to use the classes, built in your programming language, to read the source files.
File Format
The first line of the data contains the total digits in the key. You might want to save this value I can be used to separate the
key from the value using the substring function found in most programming languages
Value
Value
Value
END
The following is one of the most basic test files on the website.
File: years.txt
Sutter's Fort
Bear Flag Revolt
Sacramento state
Nachos
Buffalo wings
Great Toilet Paper Shortage
END
Reading the File
Different programming languages implement file IO in different ways. Some use classes and others use more primitive or
ingrained features. This will take the form of either a While Loop or a Do Loop. In all cases, your main testing class will read
the contents of the file and it to a instance of your linkedlist class.
Do not make this a method in your LinkedList keep it in main Why? It will make future assignments easier.
In the pseudocode below, I show the basic approach for both types of loops. Your programming language will use one or the
other. Some programming languages will return Null if the end of the file was reached. Others may contain a method on the
file reading class.
while the file has more data
read a value
list.AddTail value
end while
print list. Tostring
print list. ToStringReverse
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started