Видеодағы жұмыс
Автор: Aruna Amirtai • Декабрь 3, 2020 • Лабораторная работа • 909 Слов (4 Страниц) • 288 Просмотры
Видеодағы жұмыс (Quick Sort)
#include <iostream>
using namespace std;
int store_index = 0,i=0,j=0,z=0;
void quickSort(int* arr,int left, int right) {
if(left < right) {
int mid = right / 2;
int temp;
temp = arr[left];
arr[left] = arr[mid];
arr[mid] = temp;
mid = left;
store_index = mid + 1;
for (int i = store_index; i <= right; i++) {
if (arr[i] < arr[mid]) {
temp = arr[i];
arr[i] = arr[store_index];
arr[store_index] = temp;
store_index++;
cout << "Index iter --> " << store_index<<endl;}}
temp = arr[mid];
arr[mid] = arr[store_index - 1];
arr[store_index - 1] = temp;
mid = store_index - 1;
quickSort(arr, left, mid - 1);
quickSort(arr, mid+1, right);}}
int main(){
int arr[] = { 30, 60, 20, 50, 40, 10, 20, 90, 80, 70, 15, 20 };
int n = sizeof(arr) / sizeof(arr[0]);
cout << "Array merge sorted: \n";
quickSort(arr, 0, n-1);
for (int i = 0; i < n; i++)
cout << arr[i] << "\t";
cout <<endl;
return 0;}
[pic 1]
Тапсырма (Merge Sort)
#include <iostream>
using namespace std;
int* mas = new int[7];
voidmergesort(int* arr, int left, int right);
void quicksort(int* arr, int left, int right){
int middle, temp1, temp2, j;
middle = (left + right) / 2;
temp1 = left;
temp2 = middle + 1;
for (j = left; j <= right; j++)
if ((temp1 <= middle) && ((temp2 > right) || (arr[temp1] <arr[temp2]))){
mas[j] = arr[temp1];
temp1++;}else{
mas[j] = arr[temp2];
temp2++;}
for (j = left; j <= right; j++) arr[j] = mas[j];};inti = 0;
...