Skip to content

Instantly share code, notes, and snippets.

@affandes
Created January 2, 2024 02:21
Show Gist options
  • Save affandes/62167551a6ca06bc27e7cf286434f901 to your computer and use it in GitHub Desktop.
Save affandes/62167551a6ca06bc27e7cf286434f901 to your computer and use it in GitHub Desktop.
Contoh kode program Stack dengan tipe data long
public class Stack {
public long[] data; // tipe data long
public int top;
public Stack(int n) {
this.data = new long[n]; // tipe data long
this.top = 0;
}
public void push(long d) { // tipe data long
if (this.top < this.data.length) {
this.data[this.top] = d;
this.top++;
}
}
public long pop() { // tipe data long
if (this.top > 0) {
this.top--;
return this.data[this.top];
}
return 0;
}
public long peek() { // tipe data long
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