Professional Documents
Culture Documents
Stack: Sout ("Antrian Sudah Kosong ")
Stack: Sout ("Antrian Sudah Kosong ")
");
>CStack (int maks) { if (isFull()){ for (CItem temp = top; temp !=
public class CItem { top = bottom = null; Sout("*** Stack Penuh... Push null; temp = temp.next){
String judul; jumlah = 0; kapasitas = maks; dibatalkan ***"); } Sout(temp.judul); } } }
String penulis; int harga; } else{
CItem next; //Pointer ll >boolean isEmpty(){ > if (top == null){ //Stack CItem Pop(){
CItem (String j, String p, int h) if (jumlah == 0) return(true); belum ada isinya CItem temp = null;
{ else return (false);} top = bottom = baru; } > if (isEmpty()){
judul = j; penulis = p; harga = > else { Sout("*Stack Sdh Kosong...
h; > boolean isFull(){ baru.next = top; top = Pop Dibatalkan *");
if (kapasitas == jumlah) baru; } return (temp);
public class CStack { return(true); Sout("^^ Push Berhasil ^^"); }
CItem top, bottom; else return (false); } jumlah++; //Update Jumlah else{
int jumlah, kapasitas; Item di dalam stack
temp = top;
>if (jumlah == 1){ public class Stack { CStack s = new CStack (5); Queue
temp = top; top = bottom = s.Push(a); s.Push(b); s.Push(c);
null; } public static void s.Push(d); s.Push(e); package queue;
>else{ // Isi Stack > 1 main(String[] args) {
s.Push(f); public class Pengunjung {
temp = top; top = top.next; CItem a = new CItem ("Java",
String nama;
temp.next = null; } "Maria" , 78000);
s.Pop(); Pengunjung next; // buat link
Sout("^^ Pop Berhasil ^^"); CItem b = new CItem
Pengunjung (String n){
jumlah-- ("Oracle" , "Ghea" , 96000); s.Pop(); nama = n;
Sout("---------------------------"); CItem c = new CItem ("PHP" ,
Soutn("...:: Isi Stack ::..."); "Abdul" , 125000); s.Pop(); public class Antrian {
for (CItem t = top; t != null; t CItem d = new CItem ("C++" , Pengunjung front, rear; int
= t.next){ "Jodie" , 200000); s.Pop();
jumlah, batas;
Sout(t.judul);} return CItem e = new CItem ("SQL" , Antrian (int max){
s.Pop();
(temp);}} "Marion" , 83000);
front = rear = null; Pengunjung dequeue (){ System.out.print("Isi
rear = p;}
jumlah = 0; batas = max; Pengunjung keluar = null; Antrian ("+jumlah+") : ");
jumlah++; }
Sout("Antrian Kapasitas if (jumlah==0){ for (Pengunjung t = front; t
else {
"+max+" Dibuat ..."); Sout("Antrian Sudah Kosong "); != null; t = t.next){
Sout("Antrian Sudah Penuh");
} } System.out.print(t.nama+"
}
void enqueue (Pengunjung p){ else{ ");
Sout("Isi Antrian
if (jumlah<batas){ //masih > if (jumlah == 1){ }
("+jumlah+") : ");
ada tempat keluar = front;
for (Pengunjung t = front; t != System.out.println();
> if (jumlah==0){ front = rear = null; }
null; t = t.next){
front = rear = p; } > else{
System.out.print(t.nama+" return(keluar);
> else { front = front.next;
"); }
rear.next = p; // geser posisi terdepan }
System.out.println();
}
rear = p; }
jumlah--; }