Judul : Source Code Stack pada JAVA
link : Source Code Stack pada JAVA
Source Code Stack pada JAVA
1. Class Main
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package tumpukan;
/**
*
* @author Hermawankusuma */
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Stack tumpuk = new Stack(5);
tumpuk.push(20);
tumpuk.push(21);
tumpuk.push(12);
tumpuk.push(29);
tumpuk.push(11);
tumpuk.tampilkan();
double a = tumpuk.pop();
System.out.println("yang barusan di pop: "+ a );
tumpuk.tampilkan();
tumpuk.push(3);
tumpuk.tampilkan();
}
}
2. Class Stack
package tumpukan;
/**
*
* @author Hermawankusuma */
public class Stack {
int size;
int top;
double[] data;
public Stack(int size)
{
this.size = size;
top = -1;
data = new double[size];
}
public boolean kosong()
{
boolean ks;
if(top == -1)
{
ks = true;
}
else
{
ks = false;
}
return ks;
}
public boolean penuh()
{
if (top == size-1)
{
return true;
}
else {
return false;
}
}
public double nilaiTop()
{
return data[top];
}
public double pop()
{
double a = data[top];
top--;
return a;
}
public void push(double dt)
{
if (!penuh())
{
top++;
data[top] = dt;
}
else {
System.out.println("sudah penuh");
}
}
public void tampilkan()
{
System.out.println("isi Stack: ");
for (int i = top; i >=0; i--)
{
System.out.println(data[i]+" ");
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package tumpukan;
/**
*
* @author Hermawankusuma */
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Stack tumpuk = new Stack(5);
tumpuk.push(20);
tumpuk.push(21);
tumpuk.push(12);
tumpuk.push(29);
tumpuk.push(11);
tumpuk.tampilkan();
double a = tumpuk.pop();
System.out.println("yang barusan di pop: "+ a );
tumpuk.tampilkan();
tumpuk.push(3);
tumpuk.tampilkan();
}
}
2. Class Stack
package tumpukan;
/**
*
* @author Hermawankusuma */
public class Stack {
int size;
int top;
double[] data;
public Stack(int size)
{
this.size = size;
top = -1;
data = new double[size];
}
public boolean kosong()
{
boolean ks;
if(top == -1)
{
ks = true;
}
else
{
ks = false;
}
return ks;
}
public boolean penuh()
{
if (top == size-1)
{
return true;
}
else {
return false;
}
}
public double nilaiTop()
{
return data[top];
}
public double pop()
{
double a = data[top];
top--;
return a;
}
public void push(double dt)
{
if (!penuh())
{
top++;
data[top] = dt;
}
else {
System.out.println("sudah penuh");
}
}
public void tampilkan()
{
System.out.println("isi Stack: ");
for (int i = top; i >=0; i--)
{
System.out.println(data[i]+" ");
}
}
}
Ainsi l'article Source Code Stack pada JAVA
C'est l'article Source Code Stack pada JAVA cette fois, j'espère que cela pourra vous être bénéfique à tous. eh bien, à bientôt dans un autre article post.
Vous lisez maintenant l'article Source Code Stack pada JAVA avec l'adresse du lien https://indonesianne.blogspot.com/2013/04/source-code-stack-pada-java.html
0 Response to "Source Code Stack pada JAVA"
Posting Komentar