demobilinkedlistuos.java
来自「国外的数据结构与算法分析用书」· Java 代码 · 共 74 行
JAVA
74 行
/* DemoBilinkedListUos
* ---------------------------------------------
* Copyright (c) 2002 University of Saskatchewan
* All Rights Reserved
* -------------------------------------------- */
package dslib.demo;
import dslib.base.*;
import dslib.list.*;
import java.io.*;
/** A class that demonstrates the use of any BilinkedList. */
public class DemoBilinkedListUos extends DemoLinkedListUos
{
/** Performs a demo on the BilinkedList passed into it. Note
that this destroys the BilinkedList.
@param b The BilinkedListUos to be demo-ed. */
public DemoBilinkedListUos(BilinkedListUos b)
{
super(b);
// place the output in a text file whose name reflects the class being demonstrated
String className = b.getClass().getName();
className = className.substring(className.lastIndexOf(".")+1);
PrintWriter out = null;
try
{
out = new PrintWriter(new FileOutputStream("OutputDemo" + className + ".txt", true));
} catch (Exception e)
{
System.err.println("Error creating output file in test routine for " + className);
e.printStackTrace();
}
out.println("Testing methods of BilinkedListUos");
out.println("Inserting..... a");
b.insert("a");
out.println("Inserting..... b");
b.insert("b");
out.println("Inserting..... c");
b.insert("c");
out.println("Inserting..... d");
b.insert("d");
out.println("Inserting..... e");
b.insert("e");
out.println("Inserting..... f");
b.insert("f");
b.goLast();
out.println(b.item());
out.println("Inserting..... n");
b.insertNext("n");
out.println("Current Contents: " + b.toString());
b.goBack();
out.println(b.item());
b.goBack();
out.println(b.item());
b.deleteItem();
b.deleteLast();
out.println("The list iterated through backwards");
b.goLast();
while(!b.before())
{
out.println(b.item());
b.goBack();
}
while(!b.isEmpty() )
{
b.deleteLast();
}
out.println("Current Contents: " + b.toString());
out.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?