Untitled

 avatar
unknown
plain_text
a year ago
1.4 kB
7
Indexable
int arr[MAX_SIZE];

  // Tạo mảng ngẫu nhiên
  generateRandomArray(arr, n);

  // So sánh thời gian thực thi của các thuật toán sắp xếp

  // Chọn trực tiếp
  chrono::time_point<chrono::steady_clock> start = chrono::steady_clock::now();
  selectionSort(arr, n);
  chrono::time_point<chrono::steady_clock> end = chrono::steady_clock::now();
  chrono::duration<double> elapsed_seconds = end - start;
  cout << "Thoi gian thuc thi Selection Sort: " << elapsed_seconds.count() << " s" << endl;

  // Nổi bọt
  start = chrono::steady_clock::now();
  bubbleSort(arr, n);
  end = chrono::steady_clock::now();
  elapsed_seconds = end - start;
  cout << "Thoi gian thuc thi Bubble Sort: " << elapsed_seconds.count() << " s" << endl;

  // HeapSort
  start = chrono::steady_clock::now();
  heapSort(arr, n);
  end = chrono::steady_clock::now();
  elapsed_seconds = end - start;
  cout << "Thoi gian thuc thi Heap Sort: " << elapsed_seconds.count() << " s" << endl;

  // QuickSort
  start = chrono::steady_clock::now();
  quickSort(arr, 0, n - 1);
  end = chrono::steady_clock::now();
  elapsed_seconds = end - start;
  cout << "Thoi gian thuc thi Quick Sort: " << elapsed_seconds.count() << " s" << endl;

  // In mảng sau khi sắp xếp
  // cout << "Mang sau khi sap xep: ";
  // printArray(arr, n);

  return 0;
}
Editor is loading...
Leave a Comment