ࡱ> ikhy !7bjbj .p{{.+rr8D\(((((((($0*,>7(7(L(''' ('('''7- ''b(0(' -& -' -'<'7(7('( -r : StringLinkedListSelfContainedDemo.java public class StringLinkedListSelfContainedDemo { public static void main(String[] args) { StringLinkedListSelfContained list = new StringLinkedListSelfContained( ); list.addANodeToStart("One"); list.addANodeToStart("Two"); list.addANodeToStart("Three"); System.out.println("List has " + list.length() + " entries."); list.showList( ); if (list.onList("Three")) System.out.println("Three is on list."); else System.out.println("Three is NOT on list."); list.deleteHeadNode( ); if (list.onList("Three")) System.out.println("Three is on list."); else System.out.println("Three is NOT on list."); list.deleteHeadNode( ); // list.deleteHeadNode( ); System.out.println("Start of list:"); list.showList( ); System.out.println("End of list."); } } StringLinkedListSelfContained.java public class StringLinkedListSelfContained { private ListNode head; public StringLinkedListSelfContained( ) { head = null; } /** Displays the data on the list. */ public void showList( ) { ListNode position = head; while (position != null) { System.out.println(position.data); position = position.link; } } /** Returns the number of nodes on the list. */ public int length( ) { int count = 0; ListNode position = head; while (position != null) { count++; position = position.link; } return count; } /** Adds a node containing the data addData at the start of the list. */ public void addANodeToStart(String addData) { head = new ListNode(addData, head); } /** Deletes the first node on the list. */ public void deleteHeadNode( ) { if (head != null) head = head.link; else { System.out.println("Deleting from an empty list."); System.exit(0); } } /** Sees whether target is on the list. */ public boolean onList(String target) { return find(target) != null; } // Returns a reference to the first node containing the // target data. If target is not on the list, returns null. private ListNode find(String target) { boolean found = false; ListNode position = head; while ((position != null) && !found) { String dataAtPosition = position.data; if (dataAtPosition.equals(target)) found = true; else position = position.link; } return position; } public String[] toArray( ) { String[] anArray = new String[length( )]; ListNode position = head; int i = 0; while (position != null) { anArray[i] = position.data; i++; position = position.link; } return anArray; } private class ListNode { private String data; private ListNode link; /* public ListNode( ) { link = null; data = null; } */ public ListNode(String newData, ListNode linkValue) { data = newData; link = linkValue; } } } StringLinkedListWithIterator.java public class StringLinkedListWithIterator { private ListNode head; private ListNode current; private ListNode previous; public StringLinkedListWithIterator( ) { head = null; current = null; previous = null; } public void addANodeToStart(String addData) { head = new ListNode(addData, head); if ((current == head.link) && (current != null)) //if current is at old start node previous = head; } /** Sets iterator to beginning of list. */ public void resetIteration( ) { current = head; previous = null; } /** Returns true if iteration is not finished. */ public boolean moreToIterate( ) { return current != null; } /** Advances iterator to next node. */ public void goToNext( ) { if (current != null) { previous = current; current = current.link; } else if (head != null) { System.out.println( "Iterated too many times or uninitialized iteration."); System.exit(0); } else { System.out.println("Iterating with an empty list."); System.exit(0); } } /** Returns the data at the current node. */ public String getDataAtCurrent( ) { String result = null; if (current != null) result = current.data; else { System.out.println( "Getting data when current is not at any node."); System.exit(0); } return result; } /** Replaces the data at the current node. */ public void setDataAtCurrent(String newData) { if (current != null) { current.data = newData; } else { System.out.println( "Setting data when current is not at any node."); System.exit(0); } } /** Inserts a new node containing newData after the current node. The current node is the same after invocation as it is before. Precondition: List is not empty; current node is not beyond the entire list. */ public void insertNodeAfterCurrent(String newData) { ListNode newNode = new ListNode( ); newNode.data = newData; if (current != null) { newNode.link = current.link; current.link = newNode; } else if (head != null) { System.out.println( "Inserting when iterator is past all " + "nodes or is not initialized."); System.exit(0); } else { System.out.println( "Using insertNodeAfterCurrent with empty list."); System.exit(0); } } /** Deletes the current node. After the invocation, the current node is either the node after the deleted node or null if there is no next node. */ public void deleteCurrentNode( ) { if ((current != null) && (previous != null)) { previous.link = current.link; current = current.link; } else if ((current != null) && (previous == null)) { //At head node head = current.link; current = head; } else //current == null { System.out.println( "Deleting with uninitialized current or an empty list."); System.exit(0); } } public void showList( ) { ListNode position = head; while (position != null) { System.out.println(position.data); position = position.link; } } public int length( ) { int count = 0; ListNode position = head; while (position != null) { count++; position = position.link; } return count; } public boolean onList(String target) { return find(target) != null; } private ListNode find(String target) { boolean found = false; ListNode position = head; while ((position != null) && !found) { String dataAtPosition = position.data; if (dataAtPosition.equals(target)) found = true; else position = position.link; } return position; } public String[] toArray( ) { String[] a = new String[length( )]; ListNode position = head; int i = 0; while (position != null) { a[i] = position.data; i++; position = position.link; } return a; } private class ListNode { private String data; private ListNode link; public ListNode( ) { link = null; data = null; } public ListNode(String newData, ListNode linkValue) { data = newData; link = linkValue; } } } StringLLWithIteratorDemo.java public class StringLLWithIteratorDemo { public static void main(String[] args) { StringLinkedListWithIterator list = new StringLinkedListWithIterator( ); list.addANodeToStart("Spring"); list.addANodeToStart("Winter"); list.addANodeToStart("Fall"); list.addANodeToStart("Summer"); System.out.println("List has " + list.length( ) + " entries."); list.showList( ); System.out.println(); System.out.println("Start of list:"); list.resetIteration(); while (list.moreToIterate()) { System.out.println(list.getDataAtCurrent() + " "); list.goToNext(); } System.out.println("End of list."); System.out.println(); list.resetIteration(); // list.resetDataAtCurrent("New first item"); list.insertNodeAfterCurrent("New second item"); list.goToNext(); list.goToNext(); System.out.println("List after changing first item and "); System.out.println("inserting new second item:"); list.showList( ); System.out.println(); list.deleteCurrentNode(); System.out.println("List after deleting third item:"); list.showList( ); } } LinkedList2.java public class LinkedList2 { private ListNode2 head; public LinkedList2( ) { head = null; } public void showList( ) { ListNode2 position = head; while (position != null) { System.out.println(position.getData( )); position = position.getLink( ); } } public int length( ) { int count = 0; ListNode2 position = head; while (position != null) { count++; position = position.getLink( ); } return count; } public void addANodeToStart(E addData) { head = new ListNode2(addData, head); } public void deleteHeadNode( ) { if (head != null) { head = head.getLink( ); } else { System.out.println("Deleting from an empty list."); System.exit(0); } } public boolean onList(E target) { return find(target) != null; } private ListNode2 find(E target) { boolean found = false; ListNode2 position = head; while ((position != null) && !found) { E dataAtPosition = position.getData(); if (dataAtPosition.equals(target)) found = true; else position = position.getLink(); } return position; } } LinkedList2Demo.java public class LinkedList2Demo { public static void main(String[] args) { LinkedList2 stringList = new LinkedList2( ); stringList.addANodeToStart("Hello"); stringList.addANodeToStart("Good-bye"); stringList.showList( ); LinkedList2 numberList = new LinkedList2( ); for (int i = 0; i < 10; i++) numberList.addANodeToStart(i); numberList.deleteHeadNode(); numberList.showList( ); System.out.println(numberList.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],v,,,,,,-1-2-K-z--d7$8$H$gdJ++, ,>,A,x,},,,,,"-%---$.'.x.{.../////!/7/>/X/^///////////00{000000۶}&h&Oh'+6CJOJQJ]^JaJ&h&Oh'+5CJOJQJ\^JaJ h&Oh'+CJOJQJ^JaJ h&OhU|CJOJQJ^JaJ&h&OhJ5CJOJQJ\^JaJ h&OhJCJOJQJ^JaJ&h&OhJ6CJOJQJ]^JaJ1---.O.i....../////1/3/R/T/n/t/////d7$8$H$gd'+gdJd7$8$H$gdJ////090e0o0u0w00000001?1I1_1e1g11111111d7$8$H$gd'+00000Q1W1k1q1r1v111111122 22R2V2t2w22222223333*313\3c3l3q3333344J4N4\4`444444444444555H5K5 6 6.6163666 h&OhJCJOJQJ^JaJ&h&Oh'+6CJOJQJ]^JaJ&h&Oh'+5CJOJQJ\^JaJ h&Oh'+CJOJQJ^JaJH122@2J2W2a222222223$3&3N3T3s3333424P4a444d7$8$H$gd'+4444444445 5d55555'6K6u6{6666666 ^gd'+d7$8$H$gd'+666666666666677777777 7!7ļhhEjhJUmHnHuh&OmHnHuhJjhJUhjhUh&Oh'+CJaJ&h&Oh'+6CJOJQJ]^JaJ h&Oh'+CJOJQJ^JaJ666666677777 7!7 ^gd'+$a$ dgdJ ,1h/ =!"#$% j 666666666vvvvvvvvv666666>6666666666666666666666666666666666666666666666666hH6666666666666666666666666666666666666666666666666666666666666666662 0@P`p2( 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p8XV~ OJPJQJ_HmH nHsH tHN`N Normal dCJ_HaJmH nHsH tHDA D Default Paragraph FontRiR 0 Table Normal4 l4a (k ( 0No List 44 J0Header  H$6o6 J0 Header CharCJaJ4 @4 J0Footer  H$6o!6 J0 Footer CharCJaJPK![Content_Types].xmlN0EH-J@%ǎǢ|ș$زULTB l,3;rØJB+$G]7O٭V$ !)O^rC$y@/yH*񄴽)޵߻UDb`}"qۋJחX^)I`nEp)liV[]1M<OP6r=zgbIguSebORD۫qu gZo~ٺlAplxpT0+[}`jzAV2Fi@qv֬5\|ʜ̭NleXdsjcs7f W+Ն7`g ȘJj|h(KD- dXiJ؇(x$( :;˹! I_TS 1?E??ZBΪmU/?~xY'y5g&΋/ɋ>GMGeD3Vq%'#q$8K)fw9:ĵ x}rxwr:\TZaG*y8IjbRc|XŻǿI u3KGnD1NIBs RuK>V.EL+M2#'fi ~V vl{u8zH *:(W☕ ~JTe\O*tHGHY}KNP*ݾ˦TѼ9/#A7qZ$*c?qUnwN%Oi4 =3N)cbJ uV4(Tn 7_?m-ٛ{UBwznʜ"Z xJZp; {/<P;,)''KQk5qpN8KGbe Sd̛\17 pa>SR! 3K4'+rzQ TTIIvt]Kc⫲K#v5+|D~O@%\w_nN[L9KqgVhn R!y+Un;*&/HrT >>\ t=.Tġ S; Z~!P9giCڧ!# B,;X=ۻ,I2UWV9$lk=Aj;{AP79|s*Y;̠[MCۿhf]o{oY=1kyVV5E8Vk+֜\80X4D)!!?*|fv u"xA@T_q64)kڬuV7 t '%;i9s9x,ڎ-45xd8?ǘd/Y|t &LILJ`& -Gt/PK! ѐ'theme/theme/_rels/themeManager.xml.relsM 0wooӺ&݈Э5 6?$Q ,.aic21h:qm@RN;d`o7gK(M&$R(.1r'JЊT8V"AȻHu}|$b{P8g/]QAsم(#L[PK-![Content_Types].xmlPK-!֧6 0_rels/.relsPK-!kytheme/theme/themeManager.xmlPK-!0C)theme/theme/theme1.xmlPK-! ѐ' theme/theme/_rels/themeManager.xml.relsPK] !/p ***- $+066!7 $(,036 GnTT #&V(H*-/146!7!"#%&')*+-./12457 $&-!8@0(  B S  ?6W 0DWix*<_r0?R_q"19Li=OP]w%4<C^fgn 9Ky Z h k x ' B I l t  ! = D _ g ( 0 8 ? A I J S r y #+AI`|$%,MV!)OZBRDO'*1`r#*2?KNU $EP 1:F ;CU] '*>FIQnu!6iv # $ % d e i v !!)!B!J!!!!!!!!!!! ""V"n""""""""###7#K#_#q####### $$($7$I$_$r$$$$$$$$$$%%-%4%G%O%f%|%%%%%%%%&/&W&d&q&&&&&&&&''("(#(3(P(`(((((*):)w))))))))/*;*m********\+c+++++,(,|,,--;-E-k-------.3.6.7.8.>.?.F.G.V.p.q.r................///"/)/^d  0EWj*=_s1?S_r)0EK{=Plt49chxSW"9Ly      9 @  6 < Q X v } &&&&&&&''7'>'X'^'|''''''(#(E(M({(((((( )))')Q)W)k)q)))))**(*,*R*V*m******++*+1+\+c++++,,,B,G,\,`,q,y,,,,,,,^-`-k------!.#...1.V.q..............///"/33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333) *"H"I"o"'''1',,,,,,.........///"/ JKhE&OJeU|'+4..@''''!/@UnknownG*Ax Times New Roman5Symbol3. *Cx Arial9=  @ Consolas7.@ Calibri3> | ѹ@ A$BCambria Math"qhMJgJg' U' U!0..JHX  $PU|2!xx gjunggjungOh+'0T    (4<DLgjungNormalgjung6Microsoft Office Word@q@)u-@.- '՜.+,0 hp  Hewlett-PackardU.  Title  !"#$%&'()*+,-./012345678:;<=>?@BCDEFGHIJKLMNOPQRSTUVWYZ[\]^_abcdefgjRoot Entry F`1 -lData 91TableA -WordDocument.pSummaryInformation(XDocumentSummaryInformation8`CompObjr  F Microsoft Word 97-2003 Document MSWordDocWord.Document.89q