Created
January 2, 2024 02:25
-
-
Save affandes/34a0d808eee20e86ab3671868b98c669 to your computer and use it in GitHub Desktop.
Contoh kode program Stack dengan tipe data class Mahasiswa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Stack { | |
public Mahasiswa[] data; // tipe data Mahasiswa | |
public int top; | |
public Stack(int n) { | |
this.data = new Mahasiswa[n]; // tipe data Mahasiswa | |
this.top = 0; | |
} | |
public void push(Mahasiswa d) { // tipe data Mahasiswa | |
if (this.top < this.data.length) { | |
this.data[this.top] = d; | |
this.top++; | |
} | |
} | |
public Mahasiswa pop() { // tipe data Mahasiswa | |
if (this.top > 0) { | |
this.top--; | |
return this.data[this.top]; | |
} | |
return 0; | |
} | |
public Mahasiswa peek() { // tipe data Mahasiswa | |
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