Information Technology "IT" - level 4
504 subscribers
688 photos
40 videos
834 files
170 links
رابط قناة المراجع والملخصات والنماذج والمحاضرات
@Al_Adeeb_Group
Download Telegram
بعض اكواد مسسابقه اليوم مع الحل..

#include <iostream>
using namespace std;
int main ()
{
int x=0;
for(int I=0;I=6 ;x++,x++,I++)
{
if(x>7)
break;
cout<<x*I<<endl;
}
return 0;
}
المخرجات
0
12
24
36

#include <iostream>
using namespace std;
int main ()
{
int x=11;
for(int I=0;I=6 ;x++,x++,I++)
{
if(x>17)
break;
cout<<x/I<<endl;
}
return 0;
}
المخرجات
1
2
2
2

#include <iostream>
using namespace std;
int main ()
{
int x=3;
int y = x++ + ( ++x * x++ + ++x) + ++x;

cout<<y;

return 0;
}
المخرجات
48

#include <iostream>
using namespace std;
int main ()
{

int x =3 ,y=4;
int *px = &x,py;

py = &y;

py = px;

*px*=y-*py;

cout<<x*y;

return 0;
}
المخرجات

12

#include <iostream>
using namespace std;
int main ()
{
int a[]={1,2,3,4};
int *p =a+1;

*(p++) *= (*(p+1))--;

for(int I=0;I<4;I++)
cout<<a[I]<<endl;

return 0;
}
المخرجات
1
6
2
4
#include <iostream>
using namespace std;

int x(int a,int b)
{
for ( int i=a ; i>0; i--) {
if( a%i==0 && b%i==0) {
return i ;
}}}



int main (){
int a,b;
cin>>a>>b;
cout << x(a,b) ; }

باستخدام الدوال ايجاد القاسم المشترك الاكبر لعددين ..
#include <iostream>
using namespace std;
void p(int n)
{
int h=0 , f=1;
for ( int i=1 ; i<=n ; i++ ) {
h=0;
for ( int j=2 ; j<=i ; j++ )
if(i%j==0)
h+=f;
if(h==1)
cout << i << " " ; }}
int main () {
int n;
cin >> n;
p(n) ; }

باستخدام الدوال ايجاد الاعداد الاوليه الى n ..
#include <iostream>
using namespace std;

int x(int n)
{
int c=0;
int m;
while(n!=0) {
m=n%10;
n=n/10;
c++; }

return c; }



int main () {
int n;
cin >> n;

cout << x(n); }

باستخدام الدوال ايجاد كم عدد الخانه المدخله من قبل المستخدم ..
#include <iostream>
using namespace std;
void prime(int x)
{
string p= " the number prime";
for ( int i=2 ; i< x ; i++ )
if ( x%i ==0) {
p=" not ";
break ; }
cout << p ; }



int main () {
int x;
cin>> x;
prime(x) ; }

باستخدام الدوال فحص العدد المدخل من قبل المستخدم أإأذأإأ كان اولي او لاا ..
#include <iostream>
using namespace std;
void p(int x)
{
for ( int i=1 ; i< x ; i++ ) {
if ( x%i == 0)
cout << i << " "; }}



int main () {
int x;
cin >> x;
p(x); }

باستخدام الدوال ايجاد قواسم العدد المدخل من قبل المستخدم..
#include <iostream>
using namespace std;

int odd(int a[][3]) {
int sum=0;
for ( int i=0 ; i< 3 ; i++ ){
for ( int j=0 ; j< 3 ; j++ ) {
if ( a[i][j] %2== 1) {
sum+=a[i][j]; }}}
return sum ; }

int main () {
int a[3][3];
for ( int i=0 ; i< 3 ; i++ )
for ( int j=0 ; j< 3 ; j++ )
cin>>a[i][j];
cout << odd(a); }


باستخدام الدوال ايجاد مجموع الاعداد الفرديه في مصفوفه 3*3 ..
#include <iostream>
using namespace std;
int main () {
int a[7]={1,6,8,3,10,4,33 };
int b[7];
int x;
cin >> x;
for ( int i=0 ; i< 7 ; i++ ) {
if ( i+x>=7){
b[i+x-7] = a[i]; }
else {
b[i+x]=a[i]; }}
for ( int i=0 ; i< 7; i++ )
cout << b[i] << " " ; }


الازاحه بمقدار 3 للمصفوفه ..
#include<iostream>

#include<string>

using namespace std;

struct stack
{
char item[100];
int top;
}stk;

string post;

void push(stack &s, char ch)
{
if (s.top == 99)
return;
else
{
s.top++;
s.item[s.top] = ch;
}
}

void pop(stack &s)
{
if (s.top == -1)
return;
else
s.top--;
}

char top(stack s)
{
return s.item[s.top];
}

int isOpreator(char ch)
{
if (ch == '^' || ch == '/' || ch == '*' || ch == '+' || ch == '-')
return 1;
else
return 0;
}

int precedence(char ch)
{
if (ch == '^')
return 3;
else if (ch == '/' || ch == '*')
return 2;
else if (ch == '+' || ch == '-')
return 1;
else
return 0;
}

void postfix(string exp)
{
for (int i = 0; i < exp.length(); i++)
{
if (exp[i] == '(')
push(stk, exp[i]);

else if (exp[i] >= 'A'&&exp[i] <= 'Z' || exp[i] >= 'a'&&exp[i] <= 'z')
post += exp[i];

else if (isOpreator(exp[i]))
{
char temp = top(stk);

while (isOpreator(temp) && precedence(temp) >= precedence(exp[i]))
{
post += temp;
pop(stk);
temp = top(stk);
}

push(stk, exp[i]);

}

else if (exp[i] == ')')
{
char temp = top(stk);
while (temp != '(')
{
post += temp;
pop(stk);
temp = top(stk);
}

pop(stk);
}
}

while (stk.top > -1)
{
post += top(stk);
pop(stk);
}
}

int main()
{
stk.top = -1;

string exp = "(a*b+c)";

postfix(exp);

cout << post<<"\n";


return 0;
كود محاضرة الًيَوُمًِ هياكل بيانات عملي prefix
#include<iostream>

#include<string>

using namespace std;

struct stack
{
int top;
char item[100];
}stk;

string post,pre;

void push(stack & s, char ch)
{
if (s.top == 99)
return;
else
{
s.top++;
s.item[s.top] = ch;
}
}

void pop(stack &s)
{
if (s.top == -1)
return;
else
s.top--;
}

char top(stack s)
{
return s.item[s.top];
}

int isOpreator(char ch)
{
if (ch == '^' || ch == '*' || ch == '/' || ch == '+' || ch == '-')
return 1;
else
return 0;
}

int precdence(char ch)
{
if (ch == '^')
return 3;
else if (ch == '*' || ch == '/')
return 2;
else if (ch == '+' || ch == '-')
return 1;
else
return 0;
}

void reverse(string &exp)
{
int len = exp.length();
char temp;

for (int i = 0; i < len / 2; i++)
{
temp = exp[i];
exp[i] = exp[len - i - 1];
exp[len - i - 1] = temp;
}
}

void postfix(string exp)
{
for (int i = 0; i < exp.length(); i++)
{

if (exp[i] == '(')
push(stk, exp[i]);

else if (exp[i] >= 'A'&&exp[i] <= 'Z' || exp[i] >= 'a'&&exp[i] <= 'z')
post += exp[i];

else if (isOpreator(exp[i]))
{
char temp = top(stk);
while (isOpreator(temp) && precdence(temp) >= precdence(exp[i]))
{
post += top(stk);
pop(stk);
temp = top(stk);
}

push(stk, exp[i]);
}

else if (exp[i] == ')')
{

char temp = top(stk);
while (temp != '(')
{
post += temp;
pop(stk);
temp = top(stk);

}
pop(stk);
}


}

while (stk.top > -1)
{
post += top(stk);
pop(stk);
}
}

void prefix(string exp)
{
reverse(exp);

for (int i = 0; i < exp.length(); i++)
{

if (exp[i] == ')')
push(stk, exp[i]);

else if (exp[i] >= 'A'&&exp[i] <= 'Z' || exp[i] >= 'a'&&exp[i] <= 'z')
pre += exp[i];

else if (isOpreator(exp[i]))
{
char temp = top(stk);
while (isOpreator(temp) && precdence(temp) > precdence(exp[i]))
{
pre += top(stk);
pop(stk);
temp = top(stk);
}

push(stk, exp[i]);
}

else if (exp[i] == '(')
{

char temp = top(stk);
while (temp != ')')
{
pre += temp;
pop(stk);
temp = top(stk);

}
pop(stk);
}


}

while (stk.top > -1)
{
pre += top(stk);
pop(stk);
}

reverse(pre);
}

int main()
{

stk.top = -1;

string exp= "(a*b+c)";

postfix(exp);

cout << post << "\n";

prefix(exp);

cout<< pre<<"\n";


return 0;}
كود هياكل بيانات عملي (الطابور)


#include <iostream>
using namespace std;
const int capcity = 100;
struct queue {
int arr[capcity];
int front = -1;
int rear = -1;
bool isempty() {
if (front == -1 && rear == -1)
return true;
else return false;

}
bool isfull() {
if (rear == capcity - 1)return true;
else
{
return false;
}
}

void enq(int val) {
if (isfull()) return;
else
{
if (front == -1) {
front = 0;
arr[++rear] = val;
}
else

arr[++rear] = val;
}

}
void deq() {
if (isempty()) return;
else if (rear == front)
{
rear = -1; front = -1;
}
else
front++;
}
int getfront() {
if (isempty()) return -1;
else
return arr[front];
}



};
int main() {

queue a;
a.enq(2);
a.enq(255);
cout << a.getfront() << endl;
a.deq();
cout << a.getfront() << endl;


return 0;


}
Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰👨🏻‍💻👩🏻‍💻₰❥

عملية الاتحاد union لعناصر قائمتين احادية single linked lists :-

#include <iostream>
using namespace std;
class list
{
public:
struct Node
{
int data;
Node *next;
};
Node *head = NULL;
Node *counter = NULL;

void insert(int value)
{
Node *newnode = new Node();
newnode->data = value;
newnode->next = NULL;

if (head == NULL)
{
head = counter = newnode;
return;
}
else
{
Node *temp = head;
while (temp->next != NULL)
{
temp = temp->next;
}

temp->next = newnode;
}
}


void display_elements()
{
Node *temp = head;
while (temp != NULL)
{
cout << temp->data << "\t";
temp = temp->next;
}
}
};


void find_union(list l1, list l2)
{
bool found = false;
list union_elements;
union_elements = l2;
while (l1.counter != NULL)
{
while (union_elements.counter != NULL)
{
if (l1.counter->data == union_elements.counter->data)
{
found = true;
break;
}
union_elements.counter = union_elements.counter->next;
}
if (found == 0)
union_elements.insert(l1.counter->data);
union_elements.counter = union_elements.head;
l1.counter = l1.counter->next;
found = 0;
}
union_elements.display_elements();
cout << endl;
cout << "----------------------------------------" << endl;
}
int main()
{
list ls, lis;
ls.insert(2);
ls.insert(5);
ls.insert(3);
ls.insert(9);
cout << "----------------------------------------" << endl;
cout << "this the first linkedlist" << endl;
cout << endl;
ls.display_elements();
cout << endl;
lis.insert(5);
lis.insert(3);
lis.insert(7);
cout << "----------------------------------------" << endl;
cout << "this the second linkedlist" << endl;
cout << endl;
lis.display_elements();
cout << endl;
cout << "----------------------------------------" << endl;
cout << "this the union of tow linkedlists" << endl;
cout << endl;
find_union(ls, lis);
}


•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•


المخـ₰💻₰❥ـرجات


----------------------------------------
this the first linkedlist
2 5 3 9
----------------------------------------
this the second linkedlist
5 3 7
----------------------------------------
this the union of tow linkedlists
5 3 7 2 9
--------------------------------------
[Program finished]
Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰👨🏻‍💻👩🏻‍💻₰❥

عملية التقاطع intersection لعناصر قائمتين احادية single linked lists :-


#include <iostream>
using namespace std;

class Node
{
public:
int data;
Node *next;
};

int getCount(Node *head);
int _getIntesectionNode(int d, Node *head1, Node *head2);

int getIntesectionNode(Node *head1, Node *head2)
{
int c1 = getCount(head1);
int c2 = getCount(head2);
int d;

if (c1 > c2)
{
d = c1 - c2;
return _getIntesectionNode(d, head1, head2);
}

else
{
d = c2 - c1;
return _getIntesectionNode(d, head2, head1);
}
}

int _getIntesectionNode(int d, Node *head1, Node *head2)
{
Node *current1 = head1;
Node *current2 = head2;

for (int i = 0; i < d; i++)
{
if (current1 == NULL)
{
return -1;
}

current1 = current1->next;
}


while (current1 != NULL && current2 != NULL)
{
if (current1 == current2)
return current1->data;

current1 = current1->next;
current2 = current2->next;
}

return -1;
}

int getCount(Node *head)
{
Node *current = head;
int count = 0;
while (current != NULL)
{
count++;
current = current->next;
}

return count;
}


int main()
{
Node *newNode;

Node *head1 = new Node();
head1->data = 9;

Node *head2 = new Node();
head2->data = 6;

newNode = new Node();
newNode->data = 4;
head2->next = newNode;

newNode = new Node();
newNode->data = 3;
head2->next->next = newNode;

newNode = new Node();
newNode->data = 9;
head1->next = newNode;
head2->next->next->next = newNode;

newNode = new Node();
newNode->data = 3;
head1->next->next = newNode;
head1->next->next->next = NULL;

cout << "The node of intersection is " << getIntesectionNode(head1, head2);
}


•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•


المخـ₰💻₰❥ـرجات

The node of intersection is 9
[Program finished]
Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰...👨🏻‍💻CODE👩🏻‍💻...₰❥

#Binary_Tree
خــوارزمــيات الاشـجار الثنــائية:-
1⃣ كــود #اضــافـة العقد والأبناء.
2⃣كــود #طــباعــة العناصر مرتبة.
3⃣كــود #البــحـث عن عنصر بالأشجار الثنائية.
4⃣كــود #ايــجـاد اكبر واصغر عنصر بالشجرة.
5⃣كــود #تــرتيب الشجرة بطرقها الثلاث
preorder , inorder , postorder
6⃣كــود #حــذف عقدة من الشجرة سواء كانت تحمل ...
one child ,no child , two child

#include <iostream>
using namespace std;

struct node
{
int data;
node *left;
node *right;
};

node *NewNode(int data)
{
node *Node = new node;
Node->data = data;
Node->left = NULL;
Node->right = NULL;

return Node;
}

node *insertNode(node *&root, int val)
{
if (root == NULL)
{
node *newNode = NewNode(val);
root = newNode;
}

else if (val <= root->data)
root->left = insertNode(root->left, val);
else
root->right = insertNode(root->right, val);

return root;
}

void print(node *root)
{
if (root != NULL)
{
print(root->left);
cout << root->data << " ";
print(root->right);
}
}

node *search(node *root, int data)
{
if (root == NULL)
{
return NULL;
}
else if (root->data == data)
{
return root;
}

else if (data < root->data)
{
return search(root->left, data);
}
else if (data > root->data)
{
return search(root->right, data);
}
}

void postorder(node *root)
{
if (root)
{
postorder(root->left);
postorder(root->right);
cout << root->data << " ";
}
}

void Inorder(node *root)
{
if (root)
{
Inorder(root->left);
cout << root->data << " ";
Inorder(root->right);
}
}

void preorder(node *root)
{
if (root)
{
cout << root->data << " ";
preorder(root->left);
preorder(root->right);
}
}

node *findMin(node *root)
{
node *temp = root;
while (temp->left != NULL)
temp = temp->left;
return temp;
}

node *findMax(node *root)
{
node *temp = root;
while (temp->right != NULL)
temp = temp->right;
cout << temp->data;
return temp;
}

node *deleteNode(node *root, int data)
{
if (root == NULL)
return root;

else if (data < root->data)
root->left = deleteNode(root->left, data);

else if (data > root->data)
root->right = deleteNode(root->right, data);

else
{
//case 1 ....> No child
if (root->left == NULL && root->right == NULL)
{
delete root;
root = NULL;
}

//case 2 .....> One child
else if (root->left == NULL)
{
node *temp = root;
root = root->right;
delete temp;
}
else if (root->right == NULL)
{
node *temp = root;
root = root->left;
delete temp;
}

//case 3 .......> Two child
else
{
node *temp = findMin(root->right);
root->data = temp->data;
root->right = deleteNode(root->right, temp->data);
}
}
return root;
}

int main()
{
node *root = NULL;
node *item;
insertNode(root, 5);
insertNode(root, 1);
insertNode(root, 8);
insertNode(root, 7);
insertNode(root, 2);
insertNode(root, 9);
insertNode(root, 50);
insertNode(root, 4);

cout << "Binary sorted Tree :-" << endl;
print(root);
cout << endl;

cout << endl
<< "postorder " << endl;
postorder(root);
cout << endl
<< "*-*-*-*-*-*-*-*-*-*-*-*";

cout << endl
<< "Inorder " << endl;
Inorder(root);
cout << endl
<< "*-*-*-*-*-*-*-*-*-*-*-*";

cout << endl
<< "preorder " << endl;
preorder(root);
cout << endl
<< "*-*-*-*-*-*-*-*-*-*-*-*" << endl;

cout << endl
<< "max element : ";
findMax(root);
cout << endl
<< "*-*-*-*-*-*-*-*-*-*-*-*" << endl;

int SearchValue;
cout << "enter the value :";
cin >> SearchValue;

item = search(root, SearchValue);
if (item == NULL)
cout << "Not found ..\n";
else
cout << "found..\n";

cout << "*-*-*-*-*-*-*-*-*-*-*-*" << endl;

cout << "delete element 9:-" << endl;
root = deleteNode(root, 9);
print(root);
cout << endl;

cout << "delete element 2 :-" << endl;
root = deleteNode(root, 2);
print(root);
cout << endl;

cout << "delete element 8 :-" << endl;
root = deleteNode(root, 8);
print(root);
cout << endl;

return 0;
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰...👨🏻‍💻CODE👩🏻‍💻...₰❥

#Binary_Search_Algorithm

خـوارزمــية البــحث الـثــنائـي:-

#include <iostream>
using namespace std;

int BinarySearch(int array[], int Size, int SearchValue)
{
int low = 0;
int high = Size - 1;
int mid ;

while (low <= high)
{
mid = (low + high) / 2;

if (SearchValue == array[mid])
{
return mid;
}
else if (SearchValue > array[mid])
{
low = mid + 1;
}
else
{
high = mid - 1;
}
}
return -1;
}
int main()
{
int a[] ={11, 32, 43, 54, 65, 76, 87, 98};
int value;
cout << "enter an integer :" << endl;
cin >> value;

int result = BinarySearch(a, 8, value);

if (result >= 0)
{
cout << "the number " << a[result] << " was found at the element with index " << result << endl;
}
else
{
cout << "the number " << value << " was not found " << endl;
}
}


•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•


إ₰...Output....₰❥

enter an integer :
3
the number 3 was not found [Program finished]

-*-*-*-*-*-*-*-*-*-*-*-*-*

enter an integer :
98
the number 98 was found at the element with index 7
[Program finished]
Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰...👨🏻‍💻CODE👩🏻‍💻...₰❥

#insertion_sort
خوارزمية الترتيب بالإدراج

#include <iostream>
using namespace std;

void insertionSort(int a[], int Size)
{
int key, i, j;

for (i = 1; i < Size; i++)
{
key = a[i];
j = i;

while (j > 0 && a[j - 1] > key)
{
a[j] = a[j - 1];
j -= 1;
}

a[j] = key;
}
}

void printArray(int a[], int Size)
{
for (int i = 0; i < Size; i++)
{
cout << a[i] << " ";
}
cout << endl;
}

int main()
{
int a[11] = {9, 2, 5, 7, 1, 6, 3, 4, 8, 0, 10};
int Size = sizeof(a) / sizeof(a[0]);

cout << "Array befor sorted....\n";
printArray(a, Size);

insertionSort(a, Size);

cout << "Array after sorted....\n";
printArray(a, Size);

return 0;
}

•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•


إ₰...Output....₰❥

Array befor sorted....
9 2 5 7 1 6 3 4 8 0 10
Array after sorted....
0 1 2 3 4 5 6 7 8 9 10
[Program finished]
Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰...👨🏻‍💻CODE👩🏻‍💻...₰❥

#selection_sort

خوارزمية الترتيب بالأختيار

#include <iostream>
using namespace std;

void selectionSort(int arr[], int Size)
{
int min, i, j, temp;

for (i = 0; i < Size; i++)
{
min = i;

for (j = i + 1; j < Size; j++)
{
if (arr[j] < arr[min])
min = j;
}

temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}


void printArray(int arr[], int Size)
{
for (int i = 0; i < Size; i++)
{
cout << arr[i] << " ";
}

cout << endl;
}



int main()
{
int arr[10] = {2, 5, 4, 3, 8, 1, 9, 0, 7, 6};
int Size = sizeof(arr) / 4;

cout << "Array befor sorted....\n";
printArray(arr, Size);

selectionSort(arr, Size);

cout << "Array after sorted....\n";
printArray(arr, Size);

return 0;
}

•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•


إ₰...Output....₰❥

Array befor sorted...
2 5 4 3 8 1 9 0 7 6 Array after sorted....
0 1 2 3 4 5 6 7 8 9 [Program finished]
Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰...👨🏻‍💻CODE👩🏻‍💻...₰❥

#Merge_Sort

خــوارزمية الـفرز بالــدمج :-

#include <iostream>
using namespace std;

void merge(int arr[], int start, int mid, int end)
{
int i, j, k;
int len1 = mid - start + 1;
int len2 = end - mid;
int *L, *R;
L = new int[len1];
R = new int[len2];

for (i = 0; i < len1; i++)
L[i] = arr[start + i];
for (j = 0; j < len2; j++)
R[j] = arr[mid + 1 + j];
i = j = 0;
k = start;

while (i < len1 && j < len2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}

while (i < len1)
{
arr[k] = L[i];
i++;
k++;
}

while (j < len2)
{
arr[k] = R[j];
j++;
k++;
}

} //end merge_function

void mergeSort(int arr[], int start, int end)
{
int mid;
if (start < end)
{
mid = (start + end) / 2;
mergeSort(arr, start, mid);
mergeSort(arr, mid + 1, end);
merge(arr, start, mid, end);
}
return;
} //end mergeSort_function

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, 1, 40, 0, 8, 1, 7, 25};
int Size = sizeof(arr) / 4;

cout << "array befor sorted...\n";
print(arr, Size);

mergeSort(arr, 0, Size - 1);

cout << "array after sorted...\n";
print(arr, Size);

return 0;

} //end main



•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•


إ₰...Output....₰❥

array befor sorted...
2 5 9 1 40 0 8 1 7 25
array after sorted...
0 1 1 2 5 7 8 9 25 40 [Program finished]
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]