Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have been asking the same question for 4 days now and still no good responses.

ID: 652324 • Letter: I

Question

I have been asking the same question for 4 days now and still no good responses. Please answer it fully. I really despise this new system of asking questions because I can't award you more for my question. Make sure it works with the code + edit code I have other than stuff that shouldn't be edited below.

Using the SinglyLinkedList classes built in class, make the proper modifications to make it a DoublyLinkedList. Then, write a simple text editor. Keep the entire text in a doubly linked list, storing each line in a separate node. The program begins with a line number as a prompt to enter text. From there, you have the following choices:

enter the letter I and a string S: this will insert the string S at the end

enter the letters IA, a line number N, and string S1: inserts S1 after line N

enter the letters IB, a line number N, and string S1: inserts S1 before line N

enter the letter D with a number N: deletes the Nth line of text

enter the letter L with a number N: lists the Nth line of text

enter the letters LA: lists all lines of text

enter the letter Q: quits the program

To support each of these operations, you will have the following methods in your DoublyLinkedList class:

insert: this method will take the line of text as a string and add it to the end of the list.

insertAfter: this method takes an integer parameter (used to indicate a line number) and a string parameter, and inserts the text after the appropriate node.

insertBefore: this method takes an integer parameter (used to indicate a line number) and a string parameter, and inserts the text before the appropriate node

deleteByPosition: this method will take an integer parameter indicating which element should be deleted. For example, if 3 is passed in, the 3rd element should be deleted.

printNode: this method takes an integer parameter of the node to print. For example, if 3 is passed in, it will print the 3rd node.

printAllNodes: this method takes no parameters and prints all nodes in the list.

Included are these

Assign04Driver.java: This should not be modified.

Node.java:This will need to be modified to support a doubly linked list.

DoublyLinkedList.java: A starter class for your doubly linked list. It includes method stubs which you must implement

TextEditor.java: You must not change this interface, nor can you remove the implementation of this interface from DoublyLinkedList.java.

Here is the code I have already for you.

https://www.dropbox.com/s/0710nej3882r86v/DoublyLinkedList.java?dl=0

https://www.dropbox.com/s/pmtqbf4pvryzamz/Assign04Driver.java?dl=0

https://www.dropbox.com/s/0m971tvrkz39pf5/Node.java?dl=0

https://www.dropbox.com/s/c59rr9j4qdhir39/TextEditor.java?dl=0

In the interface and DoublyLinkedList class, there are deleteNodes methods. Do nothing with those

Explanation / Answer

public class Node<E>
{
E data;
Node<E> next;
Node<E> pre;

public Node(E d)
{
data = d;   
}
}

public class DoublyLinkedList<E> implements TextEditor<E>
{
Node<E> head;
Node<E> tail;

public DoublyLinkedList()
{   
head = null;
tail=null;
}

public boolean isEmpty()
{
return (head == null);
}

public void insert(E line)
{
Node<E> x = new Node();
x.data = line;
x.next=null;
tail.next=x;
x.prev=tail;
tail=x;



}
}   

public void insertAfter(int lineNum, E line)
{
Node<E> temp;
Node<E> x = new Node();
x.data=line;
for(int i=0,temp=head;i<lineNum;i++)
temp=temp.next;
x.next=temp.next;
temp.prev =x;
x.prev=temp;

}

public void insertBefore(int lineNum, E line)
{

Node<E> temp;
Node<E> x = new Node();
x.data=line;
for(int i=0,temp=tail;i<lineNum;i--)
temp=temp.next;
x.prev=temp.prev;
temp.prev =x;
x.next=temp;`
}

public void deleteByPosition(int position)
{
Node<E> temp,temp1;
int flag=1;
  
for(int i=0,temp=tail;i<position;i--)
{ temp1=temp;
temp=temp.next;
flag=0;}


if(flag)
{
tail=tail.prev;
tail.next=null;
}   

temp1.prev=temp.prev;
temp.prev.next=temp1;
if(temp.prev!=null)
head=temp.next;
temp=null;

  
}

public void deleteNodes(E startPos, E endPos)
{

}

public void printNode(int position)
{
Node<E> temp,temp1;
  
for(int i=0,temp=tail;i<position;i--)
{
temp=temp.next;
flag=0;}


if(flag)
  
System.out.println( "String is : " + temp.data );

System.out.println( "String is : " + temp.data );
}   


  
}

public void printAllNodes()
{
for(int i=0,temp=tail;temp.next!=null;temp=temp.next)
System.out.println( "String is : " + temp.data );

}
}
class editor

{

public static void main(String[] args) {
StringBuffer e="how to do this problem";
  
DoublyLinkedList<String> ob;

while(1)
{

System.out.println( "enter the choice is " );

Scanner reader = new Scanner(System.in);
char c = reader.nextChar();

switch(){
case I:ob.insert("hello");
Break;

case D:ob.deleteByPosition(2);
break;
case IA:ob.inserafter(2,"boys");
break;
case IB:ob.insertbefore(4,"girls");
break;
case l:ob.printnode(5);
break;
case Q:Break;

}
}

enter the letter I and a string S: this will insert the string S at the end

enter the letters IA, a line number N, and string S1: inserts S1 after line N

enter the letters IB, a line number N, and string S1: inserts S1 before line N

enter the letter D with a number N: deletes the Nth line of text

enter the letter L with a number N: lists the Nth line of text

enter the letters LA: lists all lines of text

enter the letter Q: quits the program

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote