publicclassTEst {publicstaticclassInstance{publicInstance(int i){
}
publicInstance(){
}
}
/**
* @param args
*/publicstaticvoidmain(String[] args) {
// TODO Auto-generated method stub
Instance in = new Instance(){
};
MyDoubleLink datas = new MyDoubleLink();
datas.add("aaa");
datas.add("bbb");
datas.add("ccc");
datas.print();
datas.remove("ccc");
datas.print();
for (Object d : datas) {
System.out.println(d);
}
}
}
7.1 单链表的实现
// linkList2.java// demonstrates linked list// to run this program: C>java LinkList2App////////////////////////////////////////////////////////////////
class Link
{
publicint iData; // data item (key)publicdouble dData; // data itempublic Link next; // next link in list// -------------------------------------------------------------publicLink(int id, double dd) // constructor
{
iData = id;
dData = dd;
}
// -------------------------------------------------------------publicvoiddisplayLink() // display ourself
{
System.out.print("{" + iData + ", " + dData + "} ");
}
} // end class Link////////////////////////////////////////////////////////////////
class LinkList
{
private Link first; // ref to first link on list// -------------------------------------------------------------publicLinkList() // constructor
{
first = null; // no links on list yet
}
// -------------------------------------------------------------publicvoidinsertFirst(int id, double dd)
{ // make new link
Link newLink = new Link(id, dd);
newLink.next = first; // it points to old first link
first = newLink; // now first points to this
}
// -------------------------------------------------------------public Link find(int key) // find link with given key
{ // (assumes non-empty list)
Link current = first; // start at 'first'while(current.iData != key) // while no match,
{
if(current.next == null) // if end of list,returnnull; // didn't find itelse// not end of list,
current = current.next; // go to next link
}
return current; // found it
}
// -------------------------------------------------------------public Link delete(int key) // delete link with given key
{ // (assumes non-empty list)
Link current = first; // search for link
Link previous = first;
while(current.iData != key)
{
if(current.next == null)
returnnull; // didn't find itelse
{
previous = current; // go to next link
current = current.next;
}
} // found itif(current == first) // if first link,
first = first.next; // change firstelse// otherwise,
previous.next = current.next; // bypass itreturn current;
}
// -------------------------------------------------------------publicvoiddisplayList() // display the list
{
System.out.print("List (first-->last): ");
Link current = first; // start at beginning of listwhile(current != null) // until end of list,
{
current.displayLink(); // print data
current = current.next; // move to next link
}
System.out.println("");
}
// -------------------------------------------------------------
} // end class LinkList////////////////////////////////////////////////////////////////
class LinkList2App
{
publicstaticvoidmain(String[] args)
{
LinkList theList = new LinkList(); // make list
theList.insertFirst(22, 2.99); // insert 4 items
theList.insertFirst(44, 4.99);
theList.insertFirst(66, 6.99);
theList.insertFirst(88, 8.99);
theList.displayList(); // display list
Link f = theList.find(44); // find itemif( f != null)
System.out.println("Found link with key " + f.iData);
else
System.out.println("Can't find link");
Link d = theList.delete(66); // delete itemif( d != null )
System.out.println("Deleted link with key " + d.iData);
else
System.out.println("Can't delete link");
theList.displayList(); // display list
} // end main()
} // end class LinkList2App////////////////////////////////////////////////////////////////
7.2 有序链表
// sortedList.java// demonstrates sorted list// to run this program: C>java SortedListApp////////////////////////////////////////////////////////////////
class Link
{
publiclong dData; // data itempublic Link next; // next link in list// -------------------------------------------------------------publicLink(long dd) // constructor
{ dData = dd; }
// -------------------------------------------------------------publicvoiddisplayLink() // display this link
{ System.out.print(dData + " "); }
} // end class Link////////////////////////////////////////////////////////////////
class SortedList
{
private Link first; // ref to first item// -------------------------------------------------------------publicSortedList() // constructor
{ first = null; }
// -------------------------------------------------------------publicbooleanisEmpty() // trueif no links
{ return (first==null); }
// -------------------------------------------------------------publicvoidinsert(long key) // insert, in order
{
Link newLink = new Link(key); // make new link
Link previous = null; // start at first
Link current = first;
// until end of list,while(current != null && key > current.dData)
{ // or key > current,
previous = current;
current = current.next; // go to next item
}
if(previous==null) // at beginning of list
first = newLink; // first --> newLinkelse// not at beginning
previous.next = newLink; // old prev --> newLink
newLink.next = current; // newLink --> old currnt
} // end insert()// -------------------------------------------------------------public Link remove() // return & delete first link
{ // (assumes non-empty list)
Link temp = first; // save first
first = first.next; // delete firstreturn temp; // return value
}
// -------------------------------------------------------------publicvoiddisplayList()
{
System.out.print("List (first-->last): ");
Link current = first; // start at beginning of listwhile(current != null) // until end of list,
{
current.displayLink(); // print data
current = current.next; // move to next link
}
System.out.println("");
}
} // end class SortedList////////////////////////////////////////////////////////////////
class SortedListApp
{
publicstaticvoidmain(String[] args)
{ // create new list
SortedList theSortedList = new SortedList();
theSortedList.insert(20); // insert 2 items
theSortedList.insert(40);
theSortedList.displayList(); // display list
theSortedList.insert(10); // insert 3 more items
theSortedList.insert(30);
theSortedList.insert(50);
theSortedList.displayList(); // display list
theSortedList.remove(); // remove an item
theSortedList.displayList(); // display list
} // end main()
} // end class SortedListApp////////////////////////////////////////////////////////////////
7.3 双向链表
// doublyLinked.java// demonstrates doubly-linked list// to run this program: C>java DoublyLinkedApp////////////////////////////////////////////////////////////////
class Link
{
publiclong dData; // data itempublic Link next; // next link in listpublic Link previous; // previous link in list// -------------------------------------------------------------publicLink(long d) // constructor
{ dData = d; }
// -------------------------------------------------------------publicvoiddisplayLink() // display this link
{ System.out.print(dData + " "); }
// -------------------------------------------------------------
} // end class Link////////////////////////////////////////////////////////////////
class DoublyLinkedList
{
private Link first; // ref to first itemprivate Link last; // ref to last item// -------------------------------------------------------------publicDoublyLinkedList() // constructor
{
first = null; // no items on list yet
last = null;
}
// -------------------------------------------------------------publicbooleanisEmpty() // trueif no links
{ return first==null; }
// -------------------------------------------------------------publicvoidinsertFirst(long dd) // insert at front of list
{
Link newLink = new Link(dd); // make new linkif( isEmpty() ) // if empty list,
last = newLink; // newLink <-- lastelse
first.previous = newLink; // newLink <-- old first
newLink.next = first; // newLink --> old first
first = newLink; // first --> newLink
}
// -------------------------------------------------------------publicvoidinsertLast(long dd) // insert at end of list
{
Link newLink = new Link(dd); // make new linkif( isEmpty() ) // if empty list,
first = newLink; // first --> newLinkelse
{
last.next = newLink; // old last --> newLink
newLink.previous = last; // old last <-- newLink
}
last = newLink; // newLink <-- last
}
// -------------------------------------------------------------public Link deleteFirst() // delete first link
{ // (assumes non-empty list)
Link temp = first;
if(first.next == null) // if only one item
last = null; // null <-- lastelse
first.next.previous = null; // null <-- old next
first = first.next; // first --> old nextreturn temp;
}
// -------------------------------------------------------------public Link deleteLast() // delete last link
{ // (assumes non-empty list)
Link temp = last;
if(first.next == null) // if only one item
first = null; // first --> nullelse
last.previous.next = null; // old previous --> null
last = last.previous; // old previous <-- lastreturn temp;
}
// -------------------------------------------------------------// insert dd just after keypublicbooleaninsertAfter(long key, long dd)
{ // (assumes non-empty list)
Link current = first; // start at beginningwhile(current.dData != key) // until match is found,
{
current = current.next; // move to next linkif(current == null)
returnfalse; // didn't find it
}
Link newLink = new Link(dd); // make new linkif(current==last) // if last link,
{
newLink.next = null; // newLink --> null
last = newLink; // newLink <-- last
}
else// not last link,
{
newLink.next = current.next; // newLink --> old next// newLink <-- old next
current.next.previous = newLink;
}
newLink.previous = current; // old current <-- newLink
current.next = newLink; // old current --> newLinkreturntrue; // found it, did insertion
}
// -------------------------------------------------------------public Link deleteKey(long key) // delete item w/ given key
{ // (assumes non-empty list)
Link current = first; // start at beginningwhile(current.dData != key) // until match is found,
{
current = current.next; // move to next linkif(current == null)
returnnull; // didn't find it
}
if(current==first) // found it; first item?
first = current.next; // first --> old nextelse// not first// old previous --> old next
current.previous.next = current.next;
if(current==last) // last item?
last = current.previous; // old previous <-- lastelse// not last// old previous <-- old next
current.next.previous = current.previous;
return current; // return value
}
// -------------------------------------------------------------publicvoiddisplayForward()
{
System.out.print("List (first-->last): ");
Link current = first; // start at beginningwhile(current != null) // until end of list,
{
current.displayLink(); // display data
current = current.next; // move to next link
}
System.out.println("");
}
// -------------------------------------------------------------publicvoiddisplayBackward()
{
System.out.print("List (last-->first): ");
Link current = last; // start at endwhile(current != null) // until start of list,
{
current.displayLink(); // display data
current = current.previous; // move to previous link
}
System.out.println("");
}
// -------------------------------------------------------------
} // end class DoublyLinkedList////////////////////////////////////////////////////////////////
class DoublyLinkedApp
{
publicstaticvoidmain(String[] args)
{ // make a new list
DoublyLinkedList theList = new DoublyLinkedList();
theList.insertFirst(22); // insert at front
theList.insertFirst(44);
theList.insertFirst(66);
theList.insertLast(11); // insert at rear
theList.insertLast(33);
theList.insertLast(55);
theList.displayForward(); // display list forward
theList.displayBackward(); // display list backward
theList.deleteFirst(); // delete first item
theList.deleteLast(); // delete last item
theList.deleteKey(11); // delete item with key 11
theList.displayForward(); // display list forward
theList.insertAfter(22, 77); // insert 77 after 22
theList.insertAfter(33, 88); // insert 88 after 33
theList.displayForward(); // display list forward
} // end main()
} // end class DoublyLinkedApp////////////////////////////////////////////////////////////////
public class ReverseWords {
/**
* 题目:颠倒一个句子中的词的顺序。比如: I am a student颠倒后变成:student a am I.词以空格分隔。
* 要求:
* 1.实现速度最快,移动最少
* 2.不能使用String的方法如split,indexOf等等。
* 解答:两次翻转。
*/
publ
oracle外部表是只允许只读访问,不能进行DML操作,不能创建索引,可以对外部表进行的查询,连接,排序,创建视图和创建同义词操作。
you can select, join, or sort external table data. You can also create views and synonyms for external tables. Ho
发现一个老外写的不错的jquery插件,可以实现将HTML
表格导出为excel,pdf等格式,
地址在:
https://github.com/kayalshri/
下面看个例子,实现导出表格到excel,pdf
<html>
<head>
<title>Export html table to excel an