Chuyển đến nội dung chính

Bài đăng

Spinner - <#Android>

*cấu hình Spiner dạng cơ bản   code : public class MainActivity extends AppCompatActivity { Spinner spinner ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. activity_main ); spinner = (Spinner)findViewById(R.id. spinner ); List list = new ArrayList(); list.add( "thong tin1" ); list.add( "thong tin2" ); list.add( "thong tin3" ); list.add( "thong tin4" ); list.add( "thong tin5" ); ArrayAdapter dataAdapter = new ArrayAdapter( this , android.R.layout. simple_spinner_item , list ); dataAdapter.setDropDownViewResource(android.R.layout. simple_spinner_dropdown_item ); spinner .setAdapter(dataAdapter); spinner .setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { ...

Thuật Toán Sắp xếp chèn ( Insertion Sort )

* ý tưởng của bài toán :  - lần lượt chọn các phần tử A[i] trong mảng A sau đó so sánh lần lượt với các giá trị từ A[i] -> A[0], nếu trong khoảng từ A[i]-> A[0] (" gọi tắt A[k] là phần tử trong khoảng này ")có giá trị nào nhỏ hơn giá trị đang chọn thì chuyển sang chọn phần tử kế tiếp A[i+1] nếu ngược lại thì ta đẩy dần phần tử A[k] đấy lên vị trí k+1 . * Ví Dụ : mảng A = {3, 6, 2, 1, 5}; * code : #include <iostream> #define Max 100 using namespace std;  // nhập mảng  void Nhap (int A[],int &n){ cout << "Nhap n : ";  cin >> n; for (int i = 0; i<n; i++){ cout << "A["<< i <<"] = "; cin >> A[i];  } } // thuật toán  void Insertion_Sort (int A[], int n){ for (int i = 1 ; i<n; i++ ){ int temp = A[i];  int j = i-1;  while (temp < A[j] && j>=0){ if (A[j] > temp){ A[j+1] = A[j];  ...

Thuật Toán Sắp Xếp Nổi Bọt ( Bubble Sort Algorithl )

* Ý Tưởng cho bài toán : xuất phát từ phần cuối danh sách ta tiến hành so sánh  với phần tử bên trái của nó , Nếu phần tử đang xét có khóa nhỏ hơn phần tử bên trái nó ta tiến hành đưa nó về bên trái của dãy bằng cách hoán vị 2 phần tử đó . Tiếp tục thực hiện như thế đối với bài toán có n phần tử thì sau n-1 bước như trên ta thu được dãy tăng dần (giảm dần thì người lại <khác đoạn nhỏ hơn với lớn hơn >) * VD như sau :   Mảng A= {8 , 6 , 34 , 22 , 11} các bước thuật toán thực hiện như sau :  * code :     #include <iostream> #define Max 100                                                                   using namespace std; //nhập dữ liệu void Nhap (int A[],int &n){ cout << "Nhap n : "; cin >> n; for (int i = 0; i<n; i++){ cout <<...

SELECTION_SORT

* nhập vào một mảng bất kì, sắp xếp mảng theo thứ tự tăng/giảm dần ? (sử dụng thuật toán selection_sort ) CODE  : #include <iostream> #define Max 100 using namespace std; void selection_Sort (int A[] , int n){ int t; for (int i = 0; i<(n-1); i++ ){ t = i; for (int j = i+1; j<n ; j++ ){ if (A[j] < A[i]){ t = j; } } int temp = A[i]; A[i] = A[t] ; A[t] = temp; } } void Nhap (int A[],int &n){ cout << " so luong pt : "; cin >> n; for (int i = 0; i<n; i++){ cin >> A[i] ; } } void Xuat(int A[] , int n){ cout << " mang A : "; for (int i = 0; i<n; i++){ cout << A[i] << " "; } } int main (){ int A[Max], n; Nhap(A,n); selection_Sort(A,n); Xuat(A,n); return 0; }

Các Thao Tác Trên Cây AVL

Các Thao Tác Trên Cây AVL   * Cac thao tac tren cay AVL        1. Them node vao cay AVL        2. Loai node tren cay AVL        3. Tim node tren cay AVL        4. Duyet theo thu tu truoc        5. Duyet theo thu tu giua        6. Duyet theo thu tu sau        7. chieu cao cua cay AVL code : #include <iostream> #include <stdlib.h> using namespace std; // dinh nghia Node typedef int item; typedef struct Node { item data; struct Node *left; struct Node *right; item height;   }; void init (Node *T){ T = NULL; } int Max (int a, int b){ return (a>b) ? a : b; } int height (Node *T){ if (T == NULL) return 0; return T->height; } // tao 1 node moi Node *makeNode (int data){ Node *p = new Node; p->data = data; p->left = NULL; p->right = NULL; return p; } //tim n...

chekBox trong " Android "

THAY ĐỔI MỌI THỨ cơ bản về chekbox trong  " android "  code :  package com.example.minhhien.checkbox0604; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.Toast; public class MainActivity extends AppCompatActivity {     CheckBox ckbAndroid,ckbIos,ckbPhp;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         ckbAndroid=(CheckBox) findViewById(R.id.cbAndroid);         ckbIos=(CheckBox) findViewById(R.id.cbIos);         ckbPhp=(CheckBox) findViewById(R.id.cbPhp);         ckbAndroid.setOnCheckedChangeListener(new CompoundButton.OnChecked...

EditText - Android

EditText - random 2 các số trong khoảng 2 số nhập vào bằng editText code :  package com.example.minhhien.background0604; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.Random; public class MainActivity extends AppCompatActivity {     EditText min,max;     Button btnLay,btnRanDom;     TextView tvkq;     String a;     ArrayList<Integer> arr;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         min=(EditText) findViewById(R.id.editText);         max=(EditText) f...