1 PackageLinkedlistclass;2 3 Public classNode {4 Node parents;5 Object myself;6 Node Child;7 8 PublicNode () {9 Ten } One A PublicNode (node parents, Object myself, node child) { - Super(); - This. Parents =parents; the This. myself =myself; - This. Child =Child ; - } - + PublicNode getparents () { - returnparents; + } A at Public voidsetparents (Node parents) { - This. Parents =parents; - } - - PublicObject getmyself () { - returnmyself; in } - to Public voidSetmyself (Object myself) { + This. myself =myself; - } the * PublicNode Getchild () { $ returnChild ;Panax Notoginseng } - the Public voidSetChild (Node child) { + This. Child =Child ; A } the + } - $ Public classMylinkedlist { $ PrivateNode first; - PrivateNode last; - Private intsize; the - Public voidAdd (Object obj) {WuyiNode n =NewNode (); the if(First = =NULL) { -N.setchild (NULL); Wu n.setmyself (obj); -N.setparents (NULL); AboutFirst =N; $Last =N; -}Else { - n.setparents (last); - n.setmyself (obj); AN.setchild (NULL); + the last.setchild (n); -Last =N; $ } thesize++; the } the the Public intsize () { - returnsize; in } the the PublicObject Get (intindex) { AboutNode temp =NULL; the if(First! =NULL) { thetemp =First ; the for(inti = 0; I < index; i++) { +temp =Temp.child; - } the }Bayi returntemp.myself; the } the - Public Static voidMain (string[] args) { -Mylinkedlist list =Newmylinkedlist (); theList.add ("AAA"); theList.add ("BBB"); theList.add ("CCC"); theList.add ("ddd"); -System.out.println (List.get (3)); the System.out.println (List.size ()); the } the}
Java implementation Simple LinkedList