Salah satu konsep yang sangat bermanfaat dalam ilmu komputer adalah Stack.
Stack adalah koleksi item/ data yang terurut dimana item baru akan dimasukkan atau item lama akan dihapus melalui ujung/ jalan.
Stack bersifat dinamis artinya item/data yang tidak terpakai bisa dihapus.
Dibawah ini adalah contoh Source Code nya:
Semoga bermanfaat....
:)
import java.io.*;
import java.util.*;
public class stack{
Stack stack;
String str;
int num, n;
public static void main(String[] args){
stack q = new stack();
}
public stack(){
try{
stack = new Stack();
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(ir);
System.out.println("===============");
System.out.println("===============");
System.out.println("+++++Stack+++++");
System.out.println("------In-------");
System.out.println("+++++Java++++++");
System.out.println("===============");
System.out.println("===============");
System.out.println();
System.out.print("masukkan array nya : ");
str = bf.readLine();
num = Integer.parseInt(str);
for(int i = 1; i <= num; i++){
System.out.print("masukkan angka array : ");
str = bf.readLine();
n = Integer.parseInt(str);
stack.push(n);
}
}
catch(IOException e){}
System.out.print("Hasil Tumpukan nya adalah : ");
while (!stack.empty()){
System.out.print(stack.pop() + " ");
}
}
}
import java.io.*;
import java.util.*;
public class stack{
Stack
String str;
int num, n;
public static void main(String[] args){
stack q = new stack();
}
public stack(){
try{
stack = new Stack
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(ir);
System.out.println("===============");
System.out.println("===============");
System.out.println("+++++Stack+++++");
System.out.println("------In-------");
System.out.println("+++++Java++++++");
System.out.println("===============");
System.out.println("===============");
System.out.println();
System.out.print("masukkan array nya : ");
str = bf.readLine();
num = Integer.parseInt(str);
for(int i = 1; i <= num; i++){
System.out.print("masukkan angka array : ");
str = bf.readLine();
n = Integer.parseInt(str);
stack.push(n);
}
}
catch(IOException e){}
System.out.print("Hasil Tumpukan nya adalah : ");
while (!stack.empty()){
System.out.print(stack.pop() + " ");
}
}
}
bisa buat yg stack oop ga mas?
BalasHapusbisa k0q dek......
BalasHapusQm pngen di buat kan????