Created
May 24, 2017 12:49
-
-
Save theoyrus/2a954d92877fe2a650af6e7c787f7378 to your computer and use it in GitHub Desktop.
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
import java.io.*; | |
public class QueueString{ | |
public int maxsize; | |
public String[] queuearray; | |
public int front; | |
public int rear; | |
public int jumlah; | |
public void inisiasi(int s) { | |
maxsize = s; | |
queuearray= new String[maxsize]; | |
front = rear = jumlah = 0; | |
} | |
public void enqueue(String data) { | |
if(jumlah == maxsize) | |
System.out.println("Antrian skripsi penuh. " + data + " belum bisa masuk"); | |
else { | |
queuearray[rear] = data; | |
rear = (rear+1) % maxsize; | |
jumlah++; | |
System.out.println("Silahkan. " + data + " masuk ke dalam antrian bimbingan skripsi"); | |
} | |
} | |
public String dequeue() { | |
String temp; | |
if(jumlah == 0){ | |
System.out.println("Antrian sudah kosong "); | |
return (""); | |
} else { | |
temp = queuearray[front]; | |
front = (front+1) % maxsize; | |
jumlah--; | |
System.out.println(temp + " sudah selesai bimbingan skripsi"); | |
return (temp); | |
} | |
} | |
public static void main(String[] args) | |
{ | |
QueueString queue = new QueueString(); | |
queue.inisiasi(5); | |
queue.enqueue("Rahma"); | |
queue.enqueue("Fahrudin"); | |
queue.enqueue("Suryo"); | |
queue.enqueue("Andri"); | |
queue.enqueue("Cahyo"); | |
queue.enqueue("Joko"); | |
queue.view(); | |
System.out.println("\n ___________________________ \n"); | |
queue.dequeue(); | |
queue.dequeue(); | |
queue.dequeue(); | |
queue.dequeue(); | |
queue.view(); | |
System.out.println("\n ___________________________ \n"); | |
queue.enqueue("Duwi Rahma"); | |
queue.enqueue("Ahmad Fahrudin"); | |
queue.enqueue("Suryo Prasetyo"); | |
queue.enqueue("Antonius Cahyo"); | |
queue.view(); | |
System.out.println("\n ___________________________ \n"); | |
queue.dequeue(); | |
queue.view(); | |
System.out.println("\n ___________________________ \n"); | |
queue.enqueue("M. Thohir Andriyanto"); | |
queue.view(); | |
} | |
public void view() { | |
System.out.print("Isi Queue: "); | |
if(jumlah> 0 && front < rear) | |
for(int i = front; i<=rear; i++) | |
System.out.print(queuearray[i] + ", " ); | |
else if(jumlah > 0 && rear <=front) { | |
for(int i=front; i<=maxsize-1; i++) | |
System.out.print(queuearray[i] + ", "); | |
//for(int i=0; i<rear; i++) | |
// System.out.print(queuearray[i] + ", "); | |
} | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment