Question: package LinkedList; //************************ SLLNode.java ******************************* // node in a generic singly linked list class public class SLLNode { public T info; public SLLNode next; public

package LinkedList;

//************************ SLLNode.java ******************************* // node in a generic singly linked list class

public class SLLNode { public T info; public SLLNode next; public SLLNode() { this(null,null); } public SLLNode(T el) { this(el,null); } public SLLNode(T el, SLLNode ptr) { info = el; next = ptr; } }

*******************

package LinkedList;

//************************** SLL.java ********************************* // a generic singly linked list class

public class SLL { protected SLLNode head, tail; public SLL() { head = tail = null; } public boolean isEmpty() { return head == null; } public void addToHead(T el) { head = new SLLNode(el,head); if (tail == null) tail = head; } public void addToTail(T el) { if (!isEmpty()) { tail.next = new SLLNode(el); tail = tail.next; } else head = tail = new SLLNode(el); } public T deleteFromHead() { // delete the head and return its info; if (isEmpty()) return null; T el = head.info; if (head == tail) // if only one node on the list; head = tail = null; else head = head.next; return el; } public T deleteFromTail() { // delete the tail and return its info; if (isEmpty()) return null; T el = tail.info; if (head == tail) // if only one node in the list; head = tail = null; else { // if more than one node in the list, SLLNode tmp; // find the predecessor of tail; for (tmp = head; tmp.next != tail; tmp = tmp.next); tail = tmp; // the predecessor of tail becomes tail; tail.next = null; } return el; } public void delete(T el) { // delete the node with an element el; if (!isEmpty()) if (head == tail && el.equals(head.info)) // if only one head = tail = null; // node on the list; else if (el.equals(head.info)) // if more than one node on the list; head = head.next; // and el is in the head node; else { // if more than one node in the list SLLNode pred, tmp;// and el is in a nonhead node; for (pred = head, tmp = head.next; tmp != null && !tmp.info.equals(el); pred = pred.next, tmp = tmp.next); if (tmp != null) { // if el was found; pred.next = tmp.next; if (tmp == tail) // if el is in the last node; tail = pred; } } } public void printAll() { for (SLLNode tmp = head; tmp != null; tmp = tmp.next) System.out.print(tmp.info + " "); } public boolean isInList(T el) { SLLNode tmp; for (tmp = head; tmp != null && !tmp.info.equals(el); tmp = tmp.next); return tmp != null; } }

**********

Using Java, implement the following:

package LinkedList; //************************ SLLNode.java ******************************* // node in a generic singly linked

Question ID Single linked lists Apliceation (3 oniond above. You may add more methods 9 Write a simple line editor using SLL class mentioned above. You may add more methods to SLL class if needed. Keep the entire text on a linked list, one line in a separate node Start the program with entering EDIT file, after which a prompt appears along with the line number. If the letter I is entered with a number n following it, then insert the text to be followed before line n. IfI is not followed by a number, then insert the text before the current line. If D is entered with two numbers n and m, one n, or no number following it, then delete lines n through m, line n, or the current line. Do the same with the command L, which stands for listing lines. If A is entered, then append the text to the existing lines. Entry E signifies exit and saving the text in a file. Here is an example 3> The second line 4> One more line 5> And another line // This is now line 5, not 3; 5> D 2 li 4>L /line 4, since one line was deleted; l> The first line 2> The second line / this and the following lines 3> On 4> And another line 1> The first line ne5, since L was issued from line S 3> And another line 4> I3 3> The second line e more line / now have new numbers; 1> The first line Question ID Single linked lists Apliceation (3 oniond above. You may add more methods 9 Write a simple line editor using SLL class mentioned above. You may add more methods to SLL class if needed. Keep the entire text on a linked list, one line in a separate node Start the program with entering EDIT file, after which a prompt appears along with the line number. If the letter I is entered with a number n following it, then insert the text to be followed before line n. IfI is not followed by a number, then insert the text before the current line. If D is entered with two numbers n and m, one n, or no number following it, then delete lines n through m, line n, or the current line. Do the same with the command L, which stands for listing lines. If A is entered, then append the text to the existing lines. Entry E signifies exit and saving the text in a file. Here is an example 3> The second line 4> One more line 5> And another line // This is now line 5, not 3; 5> D 2 li 4>L /line 4, since one line was deleted; l> The first line 2> The second line / this and the following lines 3> On 4> And another line 1> The first line ne5, since L was issued from line S 3> And another line 4> I3 3> The second line e more line / now have new numbers; 1> The first line

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!