Single-chain table

Source: Internet
Author: User

Public   Class Link {
Private Object Data;
Public Link next; // Note: Only a reference is saved here.

Public Link (Object Data ){
This . Data = Data;
}

Public Object PEEK (){
Return Data;
}
} Public   Class Linklist {
Private Link first;

Public   Boolean Isempty (){
Return First = Null ;
}

Public   Void Insertfirst (Object Data ){ // Write Data is written in the header
Link =   New Link (data );
Link. Next = First;
First = Link;
}

Public Link deletefirst (){
If ( ! This . Isempty ()){
Link temp = First;
First = First. Next;
Return Temp;
} Else {
Return   Null ;
}
}

Public   Void Displaylist (){
Link current = First;
While (Current ! = Null ){
System. Out. println (current. Peek () + "   " );
Current = Current. Next;
}

}

// * *********** Test ******************
Public   Static   Void Main (string [] ARGs ){
Linklist =   New Linklist ();
Linklist. insertfirst ( " Aaa " );
Linklist. insertfirst ( " Bbb " );
System. Out. println ( " DEL: " + Linklist. deletefirst () + " Data: " + Linklist. deletefirst (). Peek ());
Linklist. insertfirst ( " CCC " );
Linklist. insertfirst ( " Ddd " );
Linklist. displaylist ();
}
}

Output:
DEL: Datastructure. Link. Link @ c17164 data: AAA
Ddd
CCC

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.