Java implementation Simple LinkedList

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.