Java Learning-linked list (1)

Source: Internet
Author: User

/** * Single-link list operation * Create by Administrator * 2018/6/14 0014 * pm 2:05 **/public class Link {public int iData;    public double dData;    Public Link Next;        public Link (int ID, double dd) {this.idata = ID;    This.ddata = DD;    } public void DisplayLink () {System.out.print ("{" + IData + "," + DData + "}");    }}class linklist {private Link first;    Public linklist () {this.first = null;    public Boolean isEmpty () {//To determine if the list is empty return (first = = null);           Public link find (int key) {//Find the specified object Link current = first; Get the first dot while (current.idata! = key) {//Weight first start traversing if (Current.next = = null) {return null            ;                 Results not found}else {current = Current.next;//Get Next}} return current;        Find results} public link Delete (int key) {//Delete specified object link current = first;    Link previous = first;    while (current.idata! = key) {if (Current.next = = null) {return null;                }else {previous = current;            current = Current.next;        }} if (current = = first) {first = First.next;        }else {previous.next = Current.next;    } return current;        } public void Insertfirst (int id,double dd) {link link = new Link (ID, DD);          Link.next = First;               The reference to the storage object first = link; Assign the current object to the first} public link Deletefrst () {//delete the top list, exactly and add the opposite if (!isempty ()) {Link TEMP = Firs            T            first = First.next;        return temp;    } return null;        } public void Displaylist () {System.out.print ("List (first-->last):");        Link current = first;            while (current = null) {Current.displaylink ();        current = Current.next;    } System.out.println (""); }    public static void Main (string[] args) {linklist thelist = new linklist ();        Thelist.insertfirst (22,2.99);        Thelist.insertfirst (44,4.99);        Thelist.insertfirst (66,6.99); Thelist.insertfirst (88,8.99);

        Thelist.displaylist ();//While        (!thelist.isempty ()) {//            Link ALink = Thelist.deletefrst ();/            / System.out.print ("Deleted");//            Alink.displaylink ();//            System.out.println ("");//        }        Link f = Thelist.find (a);        if (f! = null) {            System.out.print ("Find Link:");            F.displaylink ();            System.out.println ("");            Link result = Thelist.delete (f.idata);            if (result! = null) {                System.out.print ("delete Success");                Result.displaylink ();            }        }        System.out.println ("");        Thelist.displaylist ();    }}

  

Java Learning-linked list (1)

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.