the Linked List class: import java.util.NoSuchElementException; // Linked list implementation class LList implements List { private Link head;      // Pointer to list header private Link tail;      // Pointer to last element     private Link curr;      // Access to current element     private int listSize;      // Size of list     // Constructors     LList(int size) {      // Constructor -- Ignore size         this();     }     LList() {         clear();     }     // Remove all elements     public void clear() {         curr = tail = new Link(null); // Create trailer         head = new Link(tail);        // Create header         listSize = 0;     }     // Insert "it" at current position     public boolean insert(E it) {         curr.setNext(new Link(curr.element(), curr.next()));         curr.setElement(it);         if (tail == curr) {             tail = curr.next();  // New tail         }         listSize++;         return true;     }     // Append "it" to list     public boolean append(E it) {         tail.setNext(new Link(null));         tail.setElement(it);         tail = tail.next();         listSize++;         return true;     }     // Remove and return current element     public E remove () throws NoSuchElementException {         if (curr == tail) {// Nothing to remove             throw new NoSuchElementException("remove() in LList has current of " + curr + " and size of "                                              + listSize + " that is not a a valid element");         }         E it = curr.element();                  // Remember value         curr.setElement(curr.next().element()); // Pull forward the next element         if (curr.next() == tail) {             tail = curr;   // Removed last, move tail         }         curr.setNext(curr.next().next());       // Point around unneeded link         listSize--;                             // Decrement element count         return it;                              // Return value     }     public void moveToStart() {         curr = head.next(); // Set curr at list start     }     public void moveToEnd() {         curr = tail; // Set curr at list end     }     // Move curr one step left; no change if now at front     public void prev() {         if (head.next() == curr) {             return; // No previous element         }         Link temp = head;         // March down list until we find the previous element         while (temp.next() != curr) {             temp = temp.next();         }         curr = temp;     }     // Move curr one step right; no change if now at end     public void next() { if (curr != tail) { curr = curr.next(); } }     public int length() { return listSize; } // Return list length     // Return the position of the current element     public int currPos() {         Link temp = head.next();         int i;         for (i=0; curr != temp; i++) {             temp = temp.next();         }         return i;     }     // Move down list to "pos" position     public boolean moveToPos(int pos) {         if ((pos < 0) || (pos > listSize)) {             return false;         }         curr = head.next();         for(int i=0; i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

the Linked List class:
import java.util.NoSuchElementException;
// Linked list implementation
class LList<E> implements List<E> {
private Link<E> head;      // Pointer to list header
private Link<E> tail;      // Pointer to last element

    private Link<E> curr;      // Access to current element

    private int listSize;      // Size of list

    // Constructors

    LList(int size) {      // Constructor -- Ignore size

        this();

    }

    LList() {

        clear();

    }

    // Remove all elements

    public void clear() {

        curr = tail = new Link<E>(null); // Create trailer

        head = new Link<E>(tail);        // Create header

        listSize = 0;

    }

    // Insert "it" at current position

    public boolean insert(E it) {

        curr.setNext(new Link<E>(curr.element(), curr.next()));

        curr.setElement(it);

        if (tail == curr) {

            tail = curr.next();  // New tail

        }

        listSize++;

        return true;

    }

    // Append "it" to list

    public boolean append(E it) {

        tail.setNext(new Link<E>(null));

        tail.setElement(it);

        tail = tail.next();

        listSize++;

        return true;

    }

    // Remove and return current element

    public E remove () throws NoSuchElementException {

        if (curr == tail) {// Nothing to remove

            throw new NoSuchElementException("remove() in LList has current of " + curr + " and size of "

                                             + listSize + " that is not a a valid element");

        }

        E it = curr.element();                  // Remember value

        curr.setElement(curr.next().element()); // Pull forward the next element

        if (curr.next() == tail) {

            tail = curr;   // Removed last, move tail

        }

        curr.setNext(curr.next().next());       // Point around unneeded link

        listSize--;                             // Decrement element count

        return it;                              // Return value

    }

    public void moveToStart() {

        curr = head.next(); // Set curr at list start

    }

    public void moveToEnd() {

        curr = tail; // Set curr at list end

    }

    // Move curr one step left; no change if now at front

    public void prev() {

        if (head.next() == curr) {

            return; // No previous element

        }

        Link<E> temp = head;

        // March down list until we find the previous element

        while (temp.next() != curr) {

            temp = temp.next();

        }

        curr = temp;

    }

    // Move curr one step right; no change if now at end

    public void next() { if (curr != tail) { curr = curr.next(); } }

    public int length() { return listSize; } // Return list length

    // Return the position of the current element

    public int currPos() {

        Link<E> temp = head.next();

        int i;

        for (i=0; curr != temp; i++) {

            temp = temp.next();

        }

        return i;

    }

    // Move down list to "pos" position

    public boolean moveToPos(int pos) {

        if ((pos < 0) || (pos > listSize)) {

            return false;

        }

        curr = head.next();

        for(int i=0; i<pos; i++) { curr = curr.next(); }

        return true;

    }

    // Return true if current position is at end of the list

    public boolean isAtEnd() { return curr == tail; }

    // Return current element value. Note that null gets returned if curr is at the tail

    public E getValue() throws NoSuchElementException {

        if (curr == tail) // No current element

        {

            throw new NoSuchElementException("getvalue() in LList has current of " + curr + " and size of "

                                             + listSize + " that is not a a valid element");

        }

        return curr.element();

    }

    //Tell if the list is empty or not

    public boolean isEmpty() {

        return listSize == 0;

    }

}

 

import java.util.NoSuchElementException;
// Source: OpenDSA Data Structures and Algorithms Modules Collection, CHAPTER 9 LINEAR STRUCTURES: https://opendsa-server.cs.vt.edu/ODSA/Books/Everything/html/ListADT.html
// List class ADT. Generalize the element type using Java Generics.
public interface List<E> { // List class ADT
// Remove all contents from the list, so it is once again empty
public void clear();
}
// Insert "it" at the current location
// The client must ensure that the list's capacity is not exceeded
public boolean insert (E it);
// Append "it" at the end of the list.
// The client must ensure that the list's capacity is not exceeded
public boolean append (E it);
// Remove and return the current element
public E remove() throws NoSuchElementException;
// Set the current position to the start of the list
public void moveToStart();
// Set the current position to the end of the list
public void moveToEnd();
// Move the current position one step left, no change if already at beginning
public void prev();
// Move the current position one step right, no change if already at end
public void next();
// Return the number of elements in the list
public int length();
// Return the position of the current element
public int currPos ();
// Set the current position to "pos"
public boolean moveToPos (int pos);
// Return true if current position is at end of the list
public boolean isAtEnd();
// Return the current element
public E getValue() throws NoSuchElementException;
// Tell if the list is empty or not
public boolean isEmpty();
Transcribed Image Text:import java.util.NoSuchElementException; // Source: OpenDSA Data Structures and Algorithms Modules Collection, CHAPTER 9 LINEAR STRUCTURES: https://opendsa-server.cs.vt.edu/ODSA/Books/Everything/html/ListADT.html // List class ADT. Generalize the element type using Java Generics. public interface List<E> { // List class ADT // Remove all contents from the list, so it is once again empty public void clear(); } // Insert "it" at the current location // The client must ensure that the list's capacity is not exceeded public boolean insert (E it); // Append "it" at the end of the list. // The client must ensure that the list's capacity is not exceeded public boolean append (E it); // Remove and return the current element public E remove() throws NoSuchElementException; // Set the current position to the start of the list public void moveToStart(); // Set the current position to the end of the list public void moveToEnd(); // Move the current position one step left, no change if already at beginning public void prev(); // Move the current position one step right, no change if already at end public void next(); // Return the number of elements in the list public int length(); // Return the position of the current element public int currPos (); // Set the current position to "pos" public boolean moveToPos (int pos); // Return true if current position is at end of the list public boolean isAtEnd(); // Return the current element public E getValue() throws NoSuchElementException; // Tell if the list is empty or not public boolean isEmpty();
Linked Lists
Write Java code in a new driver class that uses an linked list to complete the following:
• Prompt the user for their first name and insert every character of their first name into a list and display a representation of the list using sequence notation (in part by calling toString())
Prompt the user for their last name and insert a space and then every character of their last name into a list and display a representation of the list using sequence notation (in part by calling
toString())
Prompt the user for their middle initial and insert a space and then their middle initial, then a '. ' in the list after their first name and display a representation of the list using sequence notation (in part
by calling toString())
• Remove all but the first letter of their first name, middle name and last name and display a representation of the list using sequence notation (in part by calling toString())
Use the List interface, Link class and the LList class for this assignment. Also, add a toString method into the LList class that returns a sequence representation of the list. Do not
change the interface and you do not need to make any other adjustments to the class. Note, you do not need to upload List.java, nor Link.java.
Examples
Note, user input is in bold face blue and underlined text is required for test cases.
Please enter your first name: Joe
You entered Joe
Just the first name: | 1, o, e )
Please enter your last name: Biden
You entered Biden
With first and last names: (|1, o, e, _‚. B, i, d, e, n)
Please enter just your middle initial: R
You entered R
Full name: (1, o, e, _| R, .,. _‚. B, i, d, e, n)
Just initials: (1, R, B | )
Transcribed Image Text:Linked Lists Write Java code in a new driver class that uses an linked list to complete the following: • Prompt the user for their first name and insert every character of their first name into a list and display a representation of the list using sequence notation (in part by calling toString()) Prompt the user for their last name and insert a space and then every character of their last name into a list and display a representation of the list using sequence notation (in part by calling toString()) Prompt the user for their middle initial and insert a space and then their middle initial, then a '. ' in the list after their first name and display a representation of the list using sequence notation (in part by calling toString()) • Remove all but the first letter of their first name, middle name and last name and display a representation of the list using sequence notation (in part by calling toString()) Use the List interface, Link class and the LList class for this assignment. Also, add a toString method into the LList class that returns a sequence representation of the list. Do not change the interface and you do not need to make any other adjustments to the class. Note, you do not need to upload List.java, nor Link.java. Examples Note, user input is in bold face blue and underlined text is required for test cases. Please enter your first name: Joe You entered Joe Just the first name: | 1, o, e ) Please enter your last name: Biden You entered Biden With first and last names: (|1, o, e, _‚. B, i, d, e, n) Please enter just your middle initial: R You entered R Full name: (1, o, e, _| R, .,. _‚. B, i, d, e, n) Just initials: (1, R, B | )
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Hello, thank you for helping with this. However, the code needed is a Linked list, not array-list. Any chance you can assist with that? 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education