Single dan Double OrderedLinkedList di java

Iseng posting tentang linkedlist java, mumpung sedang belajar itu juga di Algoritma dan Struktur Data. Itung itung menuhin blog juga ^_^
langsung aja, berikut listing programnya :
yg ini untuk file Node.java

public class Node {

	int data;
	Node next;
	Node prev;
	Node(int id){
		data=id;
	}
}

file AddtLinkedList.java

public class AddtLinkedList {

	static boolean kosongCek(Node head){
		return (head==null);
	}
	static void tukar(Node nd1, Node nd2){
		Node tmp = new Node(nd1.data);
		nd1.data=nd2.data;
		nd2.data=tmp.data;
	}
	static void tampil(Node head){
		Node current=head;
		while(current!=null){
			System.out.print(current.data+" ");
			current=current.next;
		}
		System.out.println();
	}
	static void tampil(Node head, Node tail, String a){
		if (a=="maju"){
			Node current=head;
			while(current!=null){
				System.out.print(current.data+" ");
				current=current.next;
			}
			System.out.println();
		} else if (a=="mundur"){
			Node current=tail;
			while(current!=null){
				System.out.print(current.data+" ");
				current=current.prev;
			}
			System.out.println();
		}

	}
}

Continue reading