Академический Документы
Профессиональный Документы
Культура Документы
1. Jurnal no1
a. Source code
package PRAKTIKUM;
void show() {
Node current = head;
while (current != null){
System.out.print(current.data + " ");
current=current.next;
if (current == head){
System.out.print(current.data + " ");
break;
}
}
}
}
b. Hasil run
2. Jurnal no2
a. Source code
package PRAKTIKUM;
import java.util.Random;
public class Jurnal_2 {
class node{
int data;
node next;
node prev;
public node(int data){
this.data=data;
next=null;
prev=null;
}
}
node head;
node tail;
public static void main(String[] args) {
Jurnal_2 code = new Jurnal_2();
Jurnal_2 pasword = new Jurnal_2();
Random angka = new Random();
boolean cek=false;
code.addLast(1);
code.addLast(2);
code.addLast(3);
code.addLast(4);
code.addLast(5);
System.out.println("Kode Gembok dirahasiakan dari bambang");
code.print();
int x=0;
System.out.println("");
System.out.println("Mari kita Brute Force");
while(cek!=true){
pasword.addLast(angka.nextInt(5));
pasword.addLast(angka.nextInt(5));
pasword.addLast(angka.nextInt(5));
pasword.addLast(angka.nextInt(5));
pasword.addLast(angka.nextInt(5));
pasword.print();
node kode=pasword.head;
node kunci=code.head;
while(kode!=null){
if(kode.data==kunci.data){
x++;
System.out.println(x);
kode=kode.next;
kunci=kunci.next;
}else{
System.out.println("Kode Salah");
break;
}
}
if(x==4){
System.out.println("Gembok Berhasil dibuka");
cek=true;
}
x=0;
pasword.del();
}
}
public boolean IsEmpty (){
return head==null;
}
public void addLast(int data){
node baru = new node(data);
if(IsEmpty()){
head=tail=baru;
}
else{
tail.next=baru;
baru.prev=tail;
tail=baru;
tail.next=null;
}
}
public void del(){
head=tail=null;
}
b. Hasil run