Need this in Java with Eclipse Using the SinglyLinkedList classes built in class
ID: 651211 • Letter: N
Question
Need this in Java with Eclipse
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
insertAfter
insertBefore
deleteByPosition
printNode
printAllNodes
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
Modified Node.java to support doubly linked list:-
public class Node<E>
{
E data;
Node<E> prev;
Node<E> next;
public Node(E d)
{
data = d;
}
}
Modified DoublyLinkedList.java:-
public class DoublyLinkedList<E> implements TextEditor<E>
{
Node<E> head;
public DoublyLinkedList()
{
head = null;
}
public boolean isEmpty()
{
return (head == null);
}
public void insert(E line)
{
head=line;
}
public void insertAfter(int lineNum, E line)
{
int c=1;
E temp=head;
while(c<=lineNum){ //loop till lineNum
temp=temp.next;
c+=1;
}
temp=line;
}
public void insertBefore(int lineNum, E line)
{
int c=1;
E temp=head;
while(c<lineNum){ //loop till before lineNum
temp=temp.next;
c+=1;
}
temp=line;
}
public void deleteByPosition(int position)
{
int c=1;
E temp=head;
while(c<=position){
temp=temp.next;
c+=1;
}
temp.next=temp.next.next;
}
public void deleteNodes(E startPos, E endPos)
{
E temp1=head,temp2=head;
while(c<startPos){
temp1=temp1.next;
c+=1;
}
while(c<=endPos){
temp2=temp2.next;
c+=1;
}
temp1.next=temp2.next;
}
public void printNode(int position)
{
int c=1;
E temp=head;
while(c<=position){
temp=temp.next;
c+=1;
}
System.out.println(temp.data);
}
public void printAllNodes()
{
E temp=head;
while(temp!=NULL){
temp=temp.next;
System.out.println(temp.data);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.