ArrayTor – Array Simulator Version 1.0.1


Oke, inilah program pengembangan dari program dahulu yang masih berjalan di console, ArrayTor berfungsi untuk memvisualisasikan operasi-operasi yang mungkin terjadi pada suatu array, seperti :

  • Tambah elemen
  • Delete elemen
  • Cari elemen
  • Cari elemen MAX
  • Cari elemen MIN
  • Sorting Array

Sebenarnya, ini mau dibuat sekaligus sebagai program visualisasi sorting, namun sepertinya itu butuh usaha ekstra. ^^

Enjoy!

BACK-END Code

public class ArrayTwo
{
    public static int a[];
    private int ptrElmt = 0;
    private int n = 11;

    ArrayTwo()
    {
        a = new int[n];
    }
    public void addElement(int e)
    {
        a[ptrElmt] = e;
        ptrElmt ++; 
    }
    public void delElement(int d)
    {
    int batas;
    for(batas = d; batas <= 0; batas --)
    {
        a[ptrElmt - batas] = 0;

    }
    if(ptrElmt == batas)
    {
        ptrElmt = 0;
    }
    else
    {
        ptrElmt = ptrElmt - batas;
    }
        //return a;
    }
    public void displayArray()
    {
    for(ptrElmt = 0; ptrElmt <= n-1 && a[ptrElmt] != 0; ptrElmt ++)
        {
        System.out.print(+a[ptrElmt]+ " ");
        }
    }
    public void sortArray()
    {
    int b,c,d;
    d = ptrElmt;
    for(b = 1; b <= d-1 && a[b] != 0; b++)
        for(c = d-1; c >=b && a[c] != 0; c--)
        {
        if(a[c-1] > a[c])
            {
            int temp = a[c-1];
            a[c-1] = a[c];
            a[c] = temp;
            }
        }

    }
    public int searchElement(int q)
    {
    Boolean found = false;
    int i;
    for(i = 0; i <= ptrElmt-1 && a[i] != 0; i++)
        {
        if(a[i] == q)
            {
            found = true;
            break;
            }
        else
            {
            found = false;
            }
        }
    if(found == true)
        {
        return i;
        }
    else
        {
        return 9999;
        }
    }

    public int maxElement()
    {
    int max = a[0];
    for(int i = 1; i < ptrElmt && a[i] != 0; i ++)
        {
        if(a[i] >= max) max = a[i]; 
        }
    return max;
    }

    public int maxIndex()
    {
        int dex = a[0];
        int k = 0;
        for(int i = 1; i < ptrElmt && a[i] != 0; i ++)
        {
        if(a[i] >= dex) 
                {
                    dex = a[i];
                    k = i;
                }
        }

        return k;
    }

    public int minIndex()
    {
    int min = a[0];
        int k = 0;
    for(int i = 1; i < ptrElmt-1 && a[i] != 0; i ++)
        {
        if(a[i] < min) 
                {
                    min = a[i];
                    k = i;
                }
        }
    return k;
    }

    public int minElement()
    {
    int min = a[0];
    for(int i = 1; i < ptrElmt-1 && a[i] != 0; i ++)
        {
        if(a[i] < min) min = a[i];
        }
    return min;
    }

    public int getPosition()
    {
    return ptrElmt;
    }

    public int getLastElement()
    {
    return a[ptrElmt];
    }
}


Contoh Procedure 

    • sortingArray():void
public void sortingArray()
    {
        initColor();
    pos = checkArray();
        b = A.a;
    if(pos > 0)
        {
                //public void sortArray()
                //{
                    int bb,c,d;
                    d = checkArray();
                    for(bb = 1; bb <= d-1 && b[bb] != 0; bb++)
                        for(c = d-1; c >=bb && b[c] != 0; c--)
                        {
                            if(b[c-1] > b[c])
                                {
                                    int temp = b[c-1];

                                    b[c-1] = b[c];
                                    //delay();
                                    switch(c-1)
                                    {
                                        case 0: jTextField1.setText(String.valueOf(b[c-1])); break;
                                        case 1: jTextField2.setText(String.valueOf(b[c-1])); break;
                                        case 2: jTextField3.setText(String.valueOf(b[c-1])); break;
                                        case 3: jTextField4.setText(String.valueOf(b[c-1])); break;
                                        case 4: jTextField5.setText(String.valueOf(b[c-1])); break;
                                        case 5: jTextField6.setText(String.valueOf(b[c-1])); break;
                                        case 6: jTextField7.setText(String.valueOf(b[c-1])); break;
                                        case 7: jTextField8.setText(String.valueOf(b[c-1])); break;
                                        case 8: jTextField9.setText(String.valueOf(b[c-1])); break;
                                        case 9: jTextField10.setText(String.valueOf(b[c-1])); break;
                                        case 10: jTextField11.setText(String.valueOf(b[c-1])); break; 
                                    }
                                    b[c] = temp;
                                    delay();
                                    switch(c)
                                    {
                                        case 0: jTextField1.setText(String.valueOf(b[c])); break;
                                        case 1: jTextField2.setText(String.valueOf(b[c])); break;
                                        case 2: jTextField3.setText(String.valueOf(b[c])); break;
                                        case 3: jTextField4.setText(String.valueOf(b[c])); break;
                                        case 4: jTextField5.setText(String.valueOf(b[c])); break;
                                        case 5: jTextField6.setText(String.valueOf(b[c])); break;
                                        case 6: jTextField7.setText(String.valueOf(b[c])); break;
                                        case 7: jTextField8.setText(String.valueOf(b[c])); break;
                                        case 8: jTextField9.setText(String.valueOf(b[c])); break;
                                        case 9: jTextField10.setText(String.valueOf(b[c])); break;
                                        case 10: jTextField11.setText(String.valueOf(b[c])); break; 
                                    }
                                }
                        }

                //}
        A.sortArray();
        jTextPane1.setText("Pengurutan array berhasil");
// input = s.nextLine();
        }
    else
        {
        jTextPane1.setText("Array kosong, tidak ada yang bisa di-sort");
        //input = v.nextLine();
        }
    }

Screen Shooter

Proses pencarian elemen ArrayTor

Pencarian Nilai Minimum

Pencarian Nilai Maksimum

Array yang telah diurutkan + Pencarian Elemen

 download di sini

Source code : minta ke saya

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s