Assalamualaikum Wr. Wb.
Hello, at this time, i wanna discuss about queue. In data structure, queue is a special form of linear list where the operation of insertion only allowed through one side, called the back side ( REAR ) and the operation of deletion only allowed through another side, called the front side ( FRONT ) from list.
For example : Q = [ Q1 , Q2 , Q3 , … , Qn ]Here, i wanna share coding about queue with Java language. So, check this out and hope can be useful for you.
FRONT (Q) = Q1 and REAR (Q) = Qn .
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 javax.swing.JOptionPane; | |
public class queuenormal { | |
private static int i,front,rear; | |
public static String simpan[]; | |
public void Insert(){ | |
System.out.println("\n========================"); | |
System.out.println("=>>> 1.MENU INSERT <<<="); | |
System.out.println("========================"); | |
System.out.println("Data yang anda masukan :"); | |
} | |
public void input(){ | |
if ((front==1 && rear==5) || front == rear+1){ | |
System.out.println("\nPERINGATAN, OVERFLOW !!! "); | |
JOptionPane.showMessageDialog(null, "PERINGATAN, OVERFLOW !!!"); | |
Kembali(); | |
} | |
if (front==0){ | |
front=1; | |
} | |
if (rear==5){ | |
rear=0; | |
} | |
simpan[rear] = JOptionPane.showInputDialog(null, "Data ruang ke - "+(rear % 5 +1)+" ="); | |
System.out.println(simpan[rear]); | |
rear += 1; | |
} | |
public void Delete(){ | |
IsEmpty(); | |
if(front!=0){ | |
simpan[front-1]=""; | |
front += 1; | |
} | |
if(front==6){ | |
front=1; | |
} | |
if(simpan[4]=="" && simpan[3]=="" && simpan[2]=="" && simpan[1]=="" && simpan[0]=="" ){ | |
front=0; rear=0; | |
} | |
} | |
public void IsEmpty(){ | |
if(front==0 || rear==0){ | |
System.out.println("\nPERINGATAN, UNDERFLOW !!! "); | |
JOptionPane.showMessageDialog(null, "PERINGATAN, UNDERFLOW !!! "); | |
front=0; rear=0; | |
} | |
} | |
public void lihatdata(){ | |
System.out.println("\n========================"); | |
System.out.println("=>>> 3.Lihat Data <<<="); | |
System.out.println("========================"); | |
System.out.println("Data yang telah - "); | |
System.out.println("anda masukan *(Max. 5) :"); | |
System.out.println("========================\n"); | |
System.out.print("| "); | |
for( i = 0; i<=4; i++){ | |
if(simpan[i]==null){ | |
simpan[i]=""; | |
} | |
System.out.print(simpan[i]); | |
if(i<=4){ | |
System.out.print(" | "); | |
} | |
} | |
System.out.println(""); | |
System.out.println("\nFront = "+(front)); | |
System.out.println("Rear = "+(rear)); | |
} | |
public void Menu(){ | |
int pil = Integer.parseInt(JOptionPane.showInputDialog(null, "========================\n" | |
+ "==>>> MENU <<<==\n" | |
+ "========================\n" | |
+ "==>>> 1.Insert <<<==\n" | |
+ "==>>> 2.Delete <<<==\n" | |
+ "==>>> 3.Lihat Data <<<==\n" | |
+ "==>>> 4.Exit <<<==\n" | |
+ "========================\n\n" | |
+ "Silahkan Masukan Pilihan Anda : ")); | |
JOptionPane.showMessageDialog(null, "Pilihan Anda Adalah Menu Nomor : "+pil); | |
switch(pil){ | |
case 1: | |
Insert(); | |
input(); | |
break; | |
case 2: | |
Delete(); | |
break; | |
case 3: | |
lihatdata(); | |
break; | |
case 4: | |
JOptionPane.showMessageDialog(null, "Terima kasih telah mencoba program ini."); | |
System.out.println("\nExiting..."); | |
System.exit(0); | |
default: | |
JOptionPane.showMessageDialog(null, "Pilihan yang anda masukan tidak ada. \nSilahkan coba kembali."); | |
Menu(); | |
} | |
Kembali(); | |
} | |
public void Kembali(){ | |
if (JOptionPane.showConfirmDialog(null, "Apakah anda ingin kembali ?","Pertanyaan",0)==0){ | |
Menu(); | |
} | |
JOptionPane.showMessageDialog(null, "Terima kasih telah mencoba program ini."); | |
System.out.println(" "); | |
System.out.println("Exiting..."); | |
System.exit(0); | |
} | |
public static void main (String [] args){ | |
front = 0; rear = 0; | |
simpan = new String [5]; | |
queuenormal Mulai = new queuenormal(); | |
Mulai.Menu(); | |
} | |
} | |
/** | |
* | |
* author : @denmasmr | |
* you can contact me on : denmasmr@gmail.com | |
* | |
*/ |
Or you can download the coding from : (mediafire) , (megaupload).
Thanks.
Wassalamualaikum Wr. Wb.
Source theory : D. Suryadi , Pengantar Struktur Data , Gunadarma.
Artikel Terkait:
share
- Guru Kami, Pahlawan Kami.
- Belajar Augmented Reality dengan Objek Beranimasi | Unity3D 4
- ::: Tutorial Saving Energy Web | OnlineLeaf
- ::: Aplikasi keren buat blog | Paint
- Apa aja sih dampak positif & Negatif Internet itu ?
- Ber-Internetan Bersih, Aman, dan Sehat | Nawala’s Project
- Belajar Augmented Reality dengan Vuforia Extension | Unity3D 4
- Learn infix to postfix with Java | denmased.
- Bung, anda adalah Manusia paling Menyebalkan yang paling saya Kagumi.
- Pengenalan dan Sejarah Internet
- ::: Aplikasi keren buat blog | DuckMyLife
- ::: Tutorial membuat artikel terkait / related post di blog
- KOMPETISI | Blogging / Writing & Semi SEO
- Kebebasan berekspresi via Internet
struktur data