Skip to content

Instantly share code, notes, and snippets.

@theoyrus
Created June 7, 2017 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theoyrus/5d957d30dcf4eaefce28aedbfaf457a4 to your computer and use it in GitHub Desktop.
Save theoyrus/5d957d30dcf4eaefce28aedbfaf457a4 to your computer and use it in GitHub Desktop.
import java.io.*;
public class Stack_String
{
int maxsize;
String [] stackarray;
int top;
public void inisiasi (int s)
{
maxsize =s;
stackarray = new String [maxsize];
top = -1;
}
public void push (String data){
if (top >= maxsize-1)
System.out.println("Stack penuh. "+data+" tidak bisa masuk");
else {
top++;
stackarray[top] = data;
System.out.println(data+" masuk ke Stack");
}
}
public String pop () {
String temp;
if (top>=0) {
temp = stackarray [top];
System.out.println(temp+" keluar dari Stack");
top--;
return (temp);
}
else{
System.out.println("Stack sudah kosong");
return(" ");
}
}
public void view()
{
System.out.println("Isi Stack: ");
for (int i=0; i<=top; i++)
System.out.println(stackarray[i]+" ");
System.out.println("===============================================");
}
public static void main(String []args)
{
stack_arraystring stack = new stack_arraystring();
stack.inisiasi(3);
stack.push("Photoshop");
stack.push("Dreamweaver");
stack.push("Netbeans");
stack.view();
stack.push("Microsoft Word");
stack.push("Microsoft Excel");
stack.pop();
stack.pop();
stack.view();
stack.pop();
stack.pop();
stack.pop();
stack.push("Sublime Text");
stack.push("Navicat");
stack.push("Google Chrome");
stack.push("Filezilla");
stack.pop();
stack.view();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment