资源简介
Finding Maximum Contiguous Subsequence Sum using divide-and-conquer approach
代码片段和文件信息
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
public class MaxSubSum {
public static int[] a = new int[10];
static private int seqStart = 0;
static private int seqEnd = -1;
public static JTextField text1;
public static JTextField text2;
public static void main(String[] args)
{
Jframe jf = new Jframe(“test“);
JPanel panel = new JPanel();
//panel.setBackground(Color.DARK_GRAY);
panel.setLayout(new BoxLayout(panelBoxLayout.Y_AXIS));
text1 = new JTextField(“The numbers you generate will show here“);
text2 = new JTextField(“The result will show here“);
JButton btn0 = new JButton(“Generate numbers“);
JButton btn1 = new JButton(“Function 1“);
JButton btn2 = new JButton(“Function 2“);
JButton btn3 = new JButton(“Function 3“);
JButton btn4 = new JButton(“Function 4“);
btn0.addActionListener(new ButtonListener1());
btn1.addActionListener(new ButtonListener2());
btn2.addActionListener(new ButtonListener3());
btn3.addActionListener(new ButtonListener4());
btn4.addActionListener(new ButtonListener5());
panel.add(btn0);
panel.add(text1);
panel.add(btn1);
panel.add(btn2);
panel.add(btn3);
panel.add(btn4);
panel.add(text2);
jf.getContentPane().add(panel);
//btn1.setFont(bigFont);
//btn2.setFont(bigFont);
//btn3.setFont(bigFont);
jf.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
jf.setSize(300300);
jf.setVisible(true);
}
public static class ButtonListener1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String s = ““;
Random r = new Random();
for(int i=0;i<10;i++){
a[i] = r.nextInt()%100;
s += a[i]+““;
}
text1.setText(s);
}
}
public static class ButtonListener2 implements ActionListener {
public void actionPerformed(ActionEvent e) {
int maxSum;
maxSum=maxSubSum1(a);
text2.setText(“First Function:“+maxSum+“; it goes from“+seqStart+“to“+seqEnd);
}
}
public static class ButtonListener3 implements ActionListener {
public void actionPerformed(ActionEvent e) {
int maxSum;
maxSum=maxSubSum2(a);
text2.setText(“Second Function:“+maxSum+“; it goes from “+seqStart+“to “+seqEnd);
}
}
public static class ButtonListener4 implements ActionListener {
public void actionPerformed(ActionEvent e) {
int maxSum;
maxSum=maxSubSum3(a);
text2.setText(“Third Function:“+maxSum+“; it goes from “+seqStart+“to “+seqEnd);
}
}
public static class ButtonListener5 implements ActionListener {
public void actionPerformed(ActionEvent e) {
int maxSum;
maxSum=maxSubSum4(a);
text2.setText(“Fourth Function:“+maxSum+“; it goes from “+seqStart+“to “+seqEnd);
}
}
/**
* Cubic maximum contiguous subsequence sum algorithm.
* seqStart and seqEnd represent the actual best sequence.
*/
publ
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 226 2011-02-16 18:57 maxSubSum\.classpath
文件 385 2011-02-16 18:57 maxSubSum\.project
文件 1204 2011-02-17 16:53 maxSubSum\MaxSubSum$ButtonListener1.class
文件 1073 2011-02-17 16:53 maxSubSum\MaxSubSum$ButtonListener2.class
文件 1076 2011-02-17 16:53 maxSubSum\MaxSubSum$ButtonListener3.class
文件 1075 2011-02-17 16:53 maxSubSum\MaxSubSum$ButtonListener4.class
文件 1076 2011-02-17 16:53 maxSubSum\MaxSubSum$ButtonListener5.class
文件 3867 2011-02-17 16:53 maxSubSum\MaxSubSum.class
文件 6890 2011-02-17 16:53 maxSubSum\MaxSubSum.java
目录 0 2011-02-17 16:53 maxSubSum
----------- --------- ---------- ----- ----
16872 10
评论
共有 条评论