package com.example.dellfie;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class selection_sort extends Activity implements OnClickListener{
EditText txt1;
TextView txtview1;
Button b11;
int min;
String arr11;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selection_sort);
txt1=(EditText) findViewById(R.id.txt_selection_sort);
b11=(Button) findViewById(R.id.b_selection_sort);
txtview1=(TextView) findViewById(R.id.txtselect_result);
b11.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stubty
try
{
String str1=txt1.getText().toString();
String[] items = str1.replaceAll("\\[", "").replaceAll("\\]", "").split(",");
int[] results = new int[items.length];
if(arg0.getId()==R.id.b_selection_sort)
{
for(int i = 0;i<items.length;i++)
{
//Assume first element is min
min = i;
for(int j = i + 1;j<items.length;j++)
{
if(Integer.parseInt(items[j]) < Integer.parseInt(items[min])) { min = j;}
}
int temp = Integer.parseInt(items[i]);
items[i] = items[min];
items[min]= temp+"";
Toast.makeText(getApplicationContext(),items[i],Toast.LENGTH_LONG ).show();
String str11= txtview1.getText().toString();
txtview1.setText(str11+","+items[i].toString());
}
}
}
catch(Exception ee)
{
}
}
}