void RandomString(char* a, int n) { const char* box = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefjhijklmnopqrstuvwxyz0123456789"; int boxLength = strlen(box); for (int i = 0; i < n; i++) { a[i] = box[rand() % boxLength]; } a[n] = '\0'; cout << a << endl; } void QuickSortString(char* a, int left, int right) { int i, j, x, t; x = a[(left + right) / 2]; i = left; j = right; do { while (a[i] < x) i++; while (a[j] > x) j--; if (i <= j) { t = a[i]; a[i] = a[j]; a[j] = t; i++; j--; } } while (i < j); if (left < j) QuickSortString(a, left, j); if (i < right) QuickSortString(a, i, right); } int SequentialSearchChar(char* a, int n, char x) { for (int i = 0; i < n; i++) if (a[i] == x) return 1; return 0; } void MenuCau2() { char x; int sl, n; cout << "Nhap vao so phan tu cua mang: "; cin >> n; char* a = new char[n + 1]; nhaplai: system("cls"); cout << "Cau 2:" << endl; cout << "1.Create Arr \n2.Sort \n3.Search \n0.Exit" << endl; cout << "Nhap vao lua chon cua ban: "; cin>>sl; switch (sl) { case 1: cout << "Mang da duoc tao la: "; RandomString(a, n); cout << endl; system("pause"); case 2: cout << "Truoc khi sap xep: " << a << endl; QuickSortString(a, 0, n - 1); cout << "Sau khi sap xep: " << a << endl; case 3: cout << "Nhap vao ki tu ban can tim: "; cin >> x; if (SequentialSearchChar(a, n, x) == 1) cout << x << " co trong mang!" << endl; else cout << x << " khong co trong mang"<