Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
- /**
- *
- * Beschreibung
- *
- * @version 1.0 vom 26.01.2014
- * @author
- */
- public class Bubblesort2 extends JFrame {
- // Anfang Attribute
- private JTextArea jTextArea1 = new JTextArea("");
- private JScrollPane jTextArea1ScrollPane = new JScrollPane(jTextArea1);
- private JTextArea jTextArea2 = new JTextArea("");
- private JScrollPane jTextArea2ScrollPane = new JScrollPane(jTextArea2);
- private JButton jButton1 = new JButton();
- int array [] = new int [10];
- // Ende Attribute
- public Bubblesort2(String title) {
- // Frame-Initialisierung
- super(title);
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- int frameWidth = 300;
- int frameHeight = 300;
- setSize(frameWidth, frameHeight);
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- int x = (d.width - getSize().width) / 2;
- int y = (d.height - getSize().height) / 2;
- setLocation(x, y);
- setResizable(false);
- Container cp = getContentPane();
- cp.setLayout(null);
- // Anfang Komponenten
- jTextArea1ScrollPane.setBounds(8, 16, 89, 241);
- cp.add(jTextArea1ScrollPane);
- jTextArea2ScrollPane.setBounds(192, 24, 81, 233);
- cp.add(jTextArea2ScrollPane);
- jButton1.setBounds(120, 80, 57, 33);
- jButton1.setText("jButton1");
- jButton1.setMargin(new Insets(2, 2, 2, 2));
- jButton1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- jButton1_ActionPerformed(evt);
- }
- });
- cp.add(jButton1);
- // Ende Komponenten
- setVisible(true);
- } // end of public Bubblesort2
- // Anfang Methoden
- public static void quicksort (int array[],int l,int r){
- int i = l;
- int j = r;
- int mitte = array [(l+r)/2];
- while (i<j) {
- while (array[i]<mitte) {
- i++;
- } // end of if
- while (mitte<array[i]) {
- j--;
- } // end of if
- if (i<=j) {
- int merke =array[i];
- array[i] = array [j];
- array [j] = merke ;
- i++;
- j--;
- } // end of if
- if (i<j) {
- quicksort(array,l,j);
- } // end of if
- if (l<r) {
- quicksort(array,l,r);
- } // end of if
- } // end of while
- }
- public void jButton1_ActionPerformed(ActionEvent evt) {
- for (int i =0;i<10;i++) {
- array [i] = i+1;
- jTextArea1.append(Integer.toString(array[i]));
- jTextArea1.append("\n");
- } // end of for // TODO hier Quelltext einfügen
- quicksort(array,1,2);
- for (int i =0;i<10;i++) {
- array [i] = i+1;
- jTextArea2.append(Integer.toString(array[i]));
- jTextArea2.append("\n");
- } // end of for // TODO hier Quelltext einfügen
- } // end of jButton1_ActionPerformed
- // Ende Methoden
- public static void main(String[] args) {
- new Bubblesort2("Bubblesort2");
- } // end of main
- } // end of class Bubblesort2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement