方法に困っています。どの出力も正しくなく、二重リンク リストを正しく使用しているかどうかもわかりません。誰かが私が間違っていることを修正または説明できますか?
public class SlideList
{
private SlideNode head;
private SlideNode tail;
private SlideNode cursor;
public SlideList()
{
head = null;
tail = null;
cursor = null;
}
public void editCurrentSlide(String text, int lineNum) throws IllegalArgumentException
{
if(cursor==null||lineNum>5||lineNum<0)
throw new IllegalArgumentException("Slide does not exist");
cursor.getSlide().setData(text, lineNum);
}
public boolean jumpToPosition(int position)
{
if(position<0 || position>listLength())
return false;
resetCursor();
for(int x=1;x<=position;x++)
{
cursor = cursor.getNext();
}
return true;
}
public void displayCurrentSlide() throws EmptyListException
{
if(cursor==null)
throw new EmptyListException("There is no list");
displaySlide(currentSlide());
}
public void displaySlides(int start, int end) throws IllegalArgumentException
{
int length = listLength();
resetCursor();
if(start<1)
start=1;
if(end>length)
end = length;
if(start>length||length==0)
throw new IllegalArgumentException("There is no list");
resetCursor();
for(int i = 1; i < start; i++)//we can choose where to start the list with i
{
System.out.println("Inside loop1");
cursor=cursor.getNext();
}
System.out.println("start: " + start + " end: " + end);
for(int x = start; x<=end; x++)
{
System.out.println("Inside loop2");
displaySlide(x);
if(start<end)
cursor = cursor.getNext();
}
//cursor = cursor.getPrev();
}
public void displaySlide(int x)
{
System.out.print("******************************");
System.out.print(" " + x + " ");
System.out.print("******************************\n\n");
System.out.print(cursor.getSlide().toString());
System.out.print("\n******************************");
System.out.print(" " + x + " ");
System.out.print("******************************\n");
}
public int currentSlide()
{
SlideNode temp = new SlideNode();
temp = head;
int position=1;
while(temp!=cursor)
{
temp = temp.getNext();
position++;
}
return position;
}
public int listLength()
{
System.out.println("In Length of List metho");
SlideNode nodePtr = head;
int answer = 1;
while(nodePtr != tail)
{
System.out.println("In Length of List loop");
answer++;
nodePtr = nodePtr.getNext();
}
return answer;
}
public boolean removeCurrentSlide()
{
if(cursor!=null)
{
cursor = cursor.getPrev();
cursor.getNext().getNext().setPrev(cursor);
cursor.setNext(cursor.getNext().getNext());
cursor = cursor.getNext();
return true;
}
return false;
}
public void addAfterCurrent(Slide newSlide)
{
SlideNode node = new SlideNode(newSlide);
if(cursor==null)
{
addToEnd(newSlide);
}
else
{
node.setNext(cursor.getNext());
node.setPrev(cursor);
node.getNext().setPrev(node);
cursor.setNext(node);
cursor = cursor.getNext();
if(cursor.getNext() == null)
{
tail = cursor;
}
}
}
public void addToEnd(Slide newSlide)
{
SlideNode node = new SlideNode(newSlide);
if(isEmpty())
{
System.out.println("Created list");
head = node;
tail = node;
cursor = node;
}
else
{
while(cursor!=null)
{
cursor = cursor.getNext();
}
tail.setNext(node);
node.setPrev(tail);
node.setNext(head);
tail = node;
cursor = node;
}
System.out.println("Out of addToEnd");
}
public boolean isEmpty()
{
return (cursor==null);
}
public boolean moveForward()
{
if(cursor!=tail)
{
cursor = cursor.getNext();
return true;
}
else
return false;
}
public boolean moveBack()
{
if(cursor!=head)
{
cursor = cursor.getPrev();
return true;
}
else
return false;
}
public void resetCursor()
{
cursor = head;
}
public static void main(String[] args)
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
try
{
SlideList slides = new SlideList();
System.out.println("AddToEnd");
Slide newSlide = new Slide();
newSlide.setData("1", "2", "3", "4", "5");
slides.addToEnd(newSlide);
slides.displayCurrentSlide();
System.out.println("AddToEnd");
Slide newSlide1 = new Slide();
newSlide1.setData("2", "3", "3", "4", "5");
slides.addToEnd(newSlide1);
slides.displayCurrentSlide();
System.out.println("AddToEnd");
Slide newSlide2 = new Slide();
newSlide2.setData("3", "4", "5", "6", "7");
slides.addToEnd(newSlide2);
slides.displayCurrentSlide();
/*System.out.println("AddToEnd/ResetCursor");
Slide newSlide3 = new Slide();
newSlide3.setData("4", "5", "6", "7", "8");
slides.resetCursor();
slides.addToEnd(newSlide3);
slides.displayCurrentSlide();
System.out.println("Length of List");
System.out.println(slides.listLength());
System.out.println("Displaying All Slides");
slides.displaySlides(1, 10);*/
}
/*catch (IOException e)
{
System.out.println(e.getMessage());
} */
catch (EmptyListException e)
{
System.out.println(e.getMessage());
}
}
}