Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰...👨🏻💻CODE👩🏻💻...₰❥
#Quick_Sort
خــوارزمــية الفــرز الســريع :-
#include <iostream>
using namespace std;
int partition(int arr[], int low, int high)
{
int temp;
int pivot = arr[low];
int i = low + 1;
for (int j = low + 1; j <= high; j++)
{
if (arr[j] <= pivot)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
}
}
temp = arr[low];
arr[low] = arr[i - 1];
arr[i - 1] = temp;
return (i - 1);
}
void quickSort(int arr[], int low, int high)
{
if (low < high)
{
int pivot = partition(arr, low, high);
quickSort(arr, low, pivot - 1);
quickSort(arr, pivot + 1, high);
}
}
void print(int arr[], int Size)
{
for (int i = 0; i < Size; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}
int main()
{
int arr[10] = {2, 5, 9, 85, 40, 0, 8, 1, 7, 25};
int Size = sizeof(arr) / 4;
cout << "Array befor sorted....\n";
print(arr, Size);
quickSort(arr, 0, Size - 1);
cout << "Array after sorted....\n";
print(arr, Size);
return 0;
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Array befor sorted....
2 5 9 85 40 0 8 1 7 25
Array after sorted....
0 1 2 5 7 8 9 25 40 85
[Program finished]
#Quick_Sort
خــوارزمــية الفــرز الســريع :-
#include <iostream>
using namespace std;
int partition(int arr[], int low, int high)
{
int temp;
int pivot = arr[low];
int i = low + 1;
for (int j = low + 1; j <= high; j++)
{
if (arr[j] <= pivot)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
}
}
temp = arr[low];
arr[low] = arr[i - 1];
arr[i - 1] = temp;
return (i - 1);
}
void quickSort(int arr[], int low, int high)
{
if (low < high)
{
int pivot = partition(arr, low, high);
quickSort(arr, low, pivot - 1);
quickSort(arr, pivot + 1, high);
}
}
void print(int arr[], int Size)
{
for (int i = 0; i < Size; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}
int main()
{
int arr[10] = {2, 5, 9, 85, 40, 0, 8, 1, 7, 25};
int Size = sizeof(arr) / 4;
cout << "Array befor sorted....\n";
print(arr, Size);
quickSort(arr, 0, Size - 1);
cout << "Array after sorted....\n";
print(arr, Size);
return 0;
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Array befor sorted....
2 5 9 85 40 0 8 1 7 25
Array after sorted....
0 1 2 5 7 8 9 25 40 85
[Program finished]