ListNode Java Create linked list

Source: Internet
Author: User

To create a linked list in a more concise and self-creating way

1 classListNode {2     //for convenience, both of these variables use Pub1ic,3     //the variable that holds the data, directly to the int type4      Public intdata;5     //The variable that holds the node, which defaults to Nu11 .6      PublicListNode Next;7     //constructs a value that can be assigned to data at construction time8      PublicListNode () {9 //give an empty parameter construction methodTen     } One      PublicListNode (intdata) { A          This. data =data; -     } -       Public intGetData () { the          return  This. Data;  -      }   -      //Adding nodes -       Public voidAddintNewData) {  +ListNode NewNode =NewListNode (newdata); -          if( This. next==NULL){   +               This. Next =NewNode;  A}Else{   at               This. Next.add (NewData); -          }   -      }   -      //Output -       Public voidprint () { -System.out.print ( This. Data + "-");  in          if( This. next!=NULL){   -               This. Next.print ();  to          } +}

ListNode Java Create linked list

Related Article

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.