Senin, 29 Juli 2019

import java.util.Scanner;
public class ReverseSum {
public static void main(String[] args) {
int x, z, a, b, m = 0, n = 0, all;
Scanner input = new Scanner(System.in);
System.out.print("Masukkan Bilangan Pertama : ");
x = input.nextInt();
System.out.print("Masukkan Bilangan Kedua : ");
z = input.nextInt();
do{
a = x % 10;
m = m * 10 + a;
x = x / 10;
}
while(x>0);
do{
b = z % 10;
n = n * 10 + b;
z = z / 10;
}
while(z>0);
all = m + n;
System.out.println("");
System.out.println("Hasil reverse bilangan pertama : "+m);
System.out.println("Hasil reverse bilangan kedua : "+n);
System.out.println("");
System.out.println("Penjumlahan Kedua Bilangan Reverse : "+all);
}
}
package reversesum;
program penjumlahan array java

import java.util.Arrays;
public class PenjumlahanArray {
public static void main(String[] args) {
int[] a = {1, 2, 4, 8};
int[] b = {16, 32, 64, 128};
int totalA = 0;
int totalB = 0;
int total;
for(int num : a){
totalA = totalA+num;
}
for(int num : b){
totalB = totalB+num;
}
total = totalA + totalB;
System.out.println("Jumlah Nilai dari Kedua Array : "+total);
int[] ab = new int[a.length+b.length];
System.arraycopy(a, 0, ab, 0, b.length);
System.arraycopy(b, 0, ab, a.length, b.length);
System.out.print("Gabungan Data dari Kedua Array : ");
System.out.println(Arrays.toString(ab));
}
}

package penjumlahanarray;https://github.com/fanihusna109/program-array/blob/master/penjumlahan%20array.java 
https://www.istn.ac.id/  


import java.util.Collections;
https://github.com/fanihusna109/SortList.java/blob/master/SortList.java import java.util.ArrayList;
import java.util.List;
public class SortList {
public static void main(String[] args) {
List Number = new ArrayList();
Number.add("9");
Number.add("5");
Number.add("7");
Number.add("1");
Number.add("3");
System.out.println("Sebelum Diurutkan");
System.out.println(Number);
Collections.sort(Number);
System.out.println("Setelah Diurutkan");
System.out.println(Number);
}
}
package sortlist;

https://istn.ac.com
B = [16, 32, 64, 128]
# Menghitung Jumlah Nilai Kedua Array
TotalA = sum(A)
TotalB = sum(B)
Total = TotalA + TotalB
print("Jumlah Nilai Kedua Array")
print(Total)
# Menggabungkan Kedua Data Array
print("Menggabungkan Kedua Data Array")
print(A+B)
A = [1, 2, 4, 8]

https://www.istn.ac.id/ 
class Node(object):
def __init__ (self, d, n = None):
self.data = d
self.next_node = n
def get_next (self):
return self.next_node
def set_next (self, n):
self.next_node = n
def get_data (self):
return self.data
def set_data (self, d):
self.data = d
def to_string (self):
return "Node value: " + str(self.data)
class CircularLinkedList (object):
def __init__ (self, r = None):
self.root = r
self.size = 0
def get_size (self):
return self.size
def add (self, d):
if self.get_size() == 0:
self.root = Node(d)
self.root.set_next(self.root)
else:
new_node = Node (d, self.root.get_next())
self.root.set_next(new_node)
self.size += 1
def remove (self, d):
this_node = self.root
prev_node = None
while True:
if this_node.get_data() == d:
if prev_node is not None:
prev_node.set_next(this_node.get_next())
else:
while this_node.get_next() != self.root:
this_node = this_node.get_next()
this_node.set_next(self.root.get_next())
self.root = self.root.get_next()
self.size -= 1
return True
elif this_node.get_next() == self.root:
return False
prev_node = this_node
this_node = this_node.get_next()
def find (self, d):
this_node = self.root
while True:
if this_node.get_data() == d:
return True
elif this_node.get_next() == self.root:
return False
this_node = this_node.get_next()
def print_list (self):
print ("Print List..........")
if self.root is None:
return
this_node = self.root
print (this_node.to_string())
while this_node.get_next() != self.root:
this_node = this_node.get_next()
print (this_node.to_string())
def main():
myList = CircularLinkedList()
myList.add(6)
myList.add(7)
myList.add(4)
myList.add(8)
myList.add(2)
print("Find 8", myList.find(8))
print("Find 13", myList.find(13))
cur = myList.root
print (cur.to_string())
for i in range(8):
cur = cur.get_next();
print (cur.to_string())
print("size="+str(myList.get_size()))
myList.print_list()
myList.remove(8)
print("size="+str(myList.get_size()))
print("Remove 7", myList.remove(7))
print("size="+str(myList.get_size()))
myList.remove(2)
myList.print_list()
main()
# Circular Linked List


 https://www.istn.ac.id/
class Node(object):
def __init__ (self, d, n = None, p = None):
self.data = d
self.next_node = n
self.prev_node = p
def get_next (self):
return self.next_node
def set_next (self, n):
self.next_node = n
def get_prev (self):
return self.prev_node
def set_prev (self, p):
self.prev_node = p
def get_data (self):
return self.data
def set_data (self, d):
self.data = d
class LinkedList (object):
def __init__(self, r = None):
self.root = r
self.size = 0
def get_size (self):
return self.size
def add (self, d):
new_node = Node (d, self.root)
if self.root:
self.root.set_prev(new_node)
self.root = new_node
self.size += 1
def remove (self, d):
this_node = self.root
while this_node:
if this_node.get_data() == d:
next = this_node.get_next()
prev = this_node.get_prev()
if next:
next.set_prev(prev)
if prev:
prev.set_next(next)
else:
self.root = this_node
self.size -= 1
return True # data removed
else:
this_node = this_node.get_next()
return False # data not found
def find (self, d):
this_node = self.root
while this_node:
if this_node.get_data() == d:
return d
else:
this_node = this_node.get_next()
return None
myList = LinkedList()
myList.add(2)
myList.add(4)
myList.add(10)
myList.remove(4)
print(myList.remove(10))
print(myList.find(2))
# Doubly Linked Listhttps://github.com/fanihusna109/Doubly-Linked-List.py/blob/master/Doubly%20Linked%20List.py 
https://www.istn.ac.id/ 

program sort list phyton
print("Mengecek List awal")
print(List)
print("Menambahkan Angka pada List")
List.insert(0,4)
print(List)
print("Mengurutkan List")
List.sort()
print(List)
List = [2,9,1,5,3,8,7,6,0,10]
https://github.com/fanihusna109/Sort-List.py
https://www.istn.ac.id/    

Minggu, 28 Juli 2019

Circular Linked List Java

Circular Linked List Java

Berikut ini merupakan contoh program sederhana Circular Linked List dalam Java :

Contoh Source Code :

public class CircularLL{
    static class Node{
        int data;
        Node next;
     }
    static Node addToEmpty(Node last,int data){
        if (last !=null)
            return last;
       
        Node temp = new Node ();
        temp.data = data;
        last = temp;
        last.next = last;
       
        return last;
    }
   
static Node addBegin(Node last,int data){
    if(last == null)
        return addToEmpty(last, data);
   
    Node temp = new Node ();
   
    temp.data = data;
    temp.next = last.next;
    last.next = temp;
   
    return last;
}

static Node addEnd (Node last,int data){
    if (last == null)
        return addToEmpty(last, data);
   
    Node temp = new Node();
   
    temp.data = data;
    temp.next = last.next;
    last.next = temp;
    last = temp;
   
    return last;
}

static Node addAfter(Node last,int data,int item){
    if (last == null)
        return null;
   
    Node temp,p;
    p=last.next;
   
    do{
        if(p.data==item){
            temp = new Node ();
            temp.data = data;
            temp.next = p.next;
            p.next = temp;
           
            if(p==last)
                last = temp;
            return last;
        }
        p=p.next;
    }
    while (p!=last.next);
   
    System.out.println(item+"Tidak tersedia dalam List");
    return last;
}

static void traverse(Node last){
    Node p;
    if (last == null){
        System.out.println("List Kosong");
        return;
    }
    p=last.next;
   
    do{
        System.out.print(p.data+"");
        p=p.next;
    }
    while (p!=last.next);
    }
public static void main (String [] args){
    Node last = null;
   
    last = addToEmpty(last,6);
    last = addBegin(last,4);
    last = addBegin(last,3);
    last = addEnd(last,10);
    last = addEnd(last,9);
    last = addEnd(last,50);
    last = addAfter(last,70,9);
   
    traverse (last);
}
}


v


https://github.com/fanihusna109/CircularLinkedList.java
https://www.istn.ac.id/