You are on page 1of 5

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package QuizASD1;
//N201410370311252_Quiz1 adalah Node
public class N201410370311252_Quiz1 {
Object data;
N201410370311252_Quiz1 next;
public N201410370311252_Quiz1(Object data){
this.data=data;
}
public N201410370311252_Quiz1(){
}
//public void SingleList2 {
N201410370311252_Quiz1 head;
N201410370311252_Quiz1 tail;
int size;
public void inisialisasi(){
head = tail = null;
}
public boolean isEmpty(){
return size==0;
}
public int size(){
return size;
}
public void addFirst (Object o){
N201410370311252_Quiz1 input = new N201410370311252_Quiz1();
input.data=o;
if(isEmpty()){
head=input;
tail=input;
}
else{
input.next=head;
head=input;
}
size++;

}
public void addLast(Object o){
N201410370311252_Quiz1 input = new N201410370311252_Quiz1();
input.data=o;
if (isEmpty()){
head=input;
tail=input;
}
else{
tail.next=input;
tail=tail.next;
}
size++;
}
public void print (){
N201410370311252_Quiz1 temp = head;
if(!isEmpty()){
while (temp != null){
System.out.print(temp.data);
temp=temp.next;
}
}
else
System.out.println("Tidak Ada Data");
}
public void ReplaceA (){
N201410370311252_Quiz1 temp = head;
if(!isEmpty()){
while (temp != null){
int i = (Integer) temp.data;
if(i/1 == 1){
temp.data = 'A';
}
temp=temp.next;
}
}
}

public void removeFirst(){


N201410370311252_Quiz1 temp = head;
if(head == tail){
head = tail = null;
}
else {

head = temp.next;
temp = null;
}
size --;
}
public void removeLast(){
N201410370311252_Quiz1 temp = head;
if(head == tail){
head = tail = null;
}
else {
while (temp.next != tail){
temp = temp.next;
}
temp.next = null;
tail = temp;
temp = null;
}
size--;
}
public void Genap(){
N201410370311252_Quiz1 temp = head;
if(!isEmpty()){
while (temp != null){
int i = (Integer) temp.data;
if(i%2==0){
temp.data = "";
}
temp=temp.next;
}
}
}
public static void main(String[] args) {
N201410370311252_Quiz1 s = new N201410370311252_Quiz1();
s.addLast(2);
s.addLast(5);
s.addLast(2);
s.addFirst(1);
s.addFirst(1);
s.addFirst(3);
s.addFirst(0);
s.addFirst(7);
s.addFirst(3);
s.addFirst(0);
s.addFirst(1);
s.addFirst(4);
s.addFirst(1);
s.addFirst(0);

s.addFirst(2);
System.out.print("a. Menampilkan Nim = ");
s.print();
System.out.println();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
System.out.print("b. Menampilkan 3 Angka Terakhir = ");
s.print();
System.out.println();
s.removeLast();
s.removeLast();
s.removeLast();
System.out.print("c. Nim dengan Angka 1 diganti Huruf A = ");
s.addLast(2);
s.addLast(5);
s.addLast(2);
s.addFirst(1);
s.addFirst(1);
s.addFirst(3);
s.addFirst(0);
s.addFirst(7);
s.addFirst(3);
s.addFirst(0);
s.addFirst(1);
s.addFirst(4);
s.addFirst(1);
s.addFirst(0);
s.addFirst(2);
s.ReplaceA();
s.print();
System.out.println();
s.removeLast();
s.removeLast();
s.removeLast();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();

s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.removeFirst();
s.addFirst(2);
s.addFirst(5);
s.addFirst(2);
s.addFirst(1);
s.addFirst(1);
s.addFirst(3);
s.addFirst(0);
s.addFirst(7);
s.addFirst(3);
s.addFirst(0);
s.addFirst(1);
s.addFirst(4);
s.addFirst(1);
s.addFirst(0);
s.addFirst(2);
System.out.print("d. Menghapus Angka Genap Sehingga = ");
s.Genap();
s.print();
System.out.println();
}
}

You might also like