Sep 15, 2014

Contoh Double Linked List Java Netbeans

package javaapplication6;

class Node {
    String data;
    Node prev;
    Node next;
    void info() {
        System.out.println(" ");
        System.out.println("Data :"+this.data);
        System.out.println("Alamat "+this);
     
    }
 
}


public class JavaApplication6 {
    static Node head = null, tail = null;
    static void push(Node node_baru) {
        if (head == null && tail == null) {
            head = node_baru;
            tail = node_baru;
        }else {
            node_baru.prev  = tail;
            tail.next = node_baru;
            tail = node_baru;
        }
    }

    public static void main(String[] args) {
        Node ana = new Node();
        ana.data= "Ana";
        Node Nana = new Node();
        Nana.data= "Nana";
        Node Fana = new Node();
        Fana.data= "Fana";
        Node Sana = new Node();
        Sana.data= "Sana";
        push(ana);
        push(Nana);
        push(Fana);
        push(Sana);
        head.info();
        tail.info();
        head.next.next.info();
    }
 
}
Share:

1 comment:

  1. Mohegan Sun: Now Open | Casino & Resort in CT
    Mohegan 파주 출장마사지 Sun is open and excited to experience it 과천 출장마사지 all 광주광역 출장마사지 again! Mohegan sun 제천 출장샵 offers outstanding gaming, premier promotions 전라남도 출장안마 and the best of the best in

    ReplyDelete

Silahkan Tinggalkan Komentar Anda