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. 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.
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