Answered step by step
Verified Expert Solution
Link Copied!

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 AddHead(String value){
Node newNode = new Node(value);
newNode.next = head;
head = newNode;
if (tail == null){
tail = head;
}
}
// AddTail method
public void AddTail(String value){
Node newNode = new Node(value);
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 (current.next != 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){
sb.append(current.value);
if (current.next != null){
sb.append(",");
}
current = current.next;
}
return sb.toString();
}
// ToStringReverse method
public String ToStringReverse(){
if (head == null){
return "";
}
StringBuilder sb = new StringBuilder();
Node current = tail;
while (current != null){
sb.append(current.value);
if (current != head){
sb.append(",");
}
current = current.prev;
}
return sb.toString();
}
// Node class
private class Node {
private String value;
private Node next;
private Node prev; // for ToStringReverse
public Node(String 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 3: 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 1
Value 2
...
Value n
END
The following is one of the most basic test files on the website.
File: years.txt
Sutter's Fort (1839)
Bear Flag Revolt (1846)
Sacramento state (1947)
Nachos (1953)
Buffalo wings (1964)
Great Toilet Paper Shortage (2020)
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 linked-list 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 ()
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago