Skip to content

Instantly share code, notes, and snippets.

@affandes
Created January 2, 2024 02:23
Show Gist options
  • Save affandes/1fa30af64f0b651a26ad3d68d8e71ee3 to your computer and use it in GitHub Desktop.
Save affandes/1fa30af64f0b651a26ad3d68d8e71ee3 to your computer and use it in GitHub Desktop.
Contoh kode program Stack dengan tipe data String
public class Stack {
public String[] data; // tipe data String
public int top;
public Stack(int n) {
this.data = new String[n]; // tipe data String
this.top = 0;
}
public void push(String d) { // tipe data String
if (this.top < this.data.length) {
this.data[this.top] = d;
this.top++;
}
}
public String pop() { // tipe data String
if (this.top > 0) {
this.top--;
return this.data[this.top];
}
return 0;
}
public String peek() { // tipe data String
if (this.top > 0) {
return this.data[this.top-1];
}
return 0;
}
public boolean empty() {
return this.top == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment