算法的简单应用

package com.demo.calculate;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {
private int[] arr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arr = new int[]{2,3,4,5,6,7,8,9};
findViewById(R.id.btn_add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addElementToLast(11);
}
});
findViewById(R.id.btn_insert).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertElement(2,5);
}
});
findViewById(R.id.btn_delete).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteElement(2);
}
});
findViewById(R.id.btn_lineSearch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("tag",lineSearch(2)+"");
}
});
findViewById(R.id.btn_addQueue).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addQueue(10);
}
});
findViewById(R.id.btn_popQueue).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popQueue();
}
});
findViewById(R.id.btn_bubbleSort).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bubbleSort();
}
});
}

/**
 * 冒泡排序
 */
private void bubbleSort() {
    int[] arr = new int[]{3,2,5,7,4,1,0,8};
    for (int i = 0; i arr[j+1]){
                int temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
    Log.i("tag",Arrays.toString(arr));
}

/**
 * 出队
 */
private void popQueue() {
    if (arr.length==0){
        return;
    }
    int[] newArr = new int[arr.length-1];
    for (int i = 0; i arr.length-1){
        return;
    }
    int[] newArr = new int[arr.length-1];
    for (int i = 0; i arr.length-1){
        return;
    }
    for (int i = 0; i 

}

你可能感兴趣的:(算法的简单应用)