السلام عليكم ورحمة الله وبركاته ،، أسعد الله صباحكم بالرضا والنعيم ، يوجد لدي برنامج في لغة C++ حاولت بأن اصل لحل ولو كان بنسبة 90% ولكن كل محاولاتي أشعر بأنها غير صحيحة ودقيقة وتوجد محاولة بها حل الكود ولكن أغلبها خاطئة ، وقمت بأخذ صور من لقطات الشاشة من الكود والنتائج ، وأرجوا منكم مساعدتي لحل هذا البرنامج والمطلوب من البرنامج هو . . .
اكتب برنامج بلغة ++C يقوم بعملية الفرز بثلاث طرق مختلفة و هي الفقاعي و الاختيار و الاقحام باستخدام دالة لكل طريقة و بحيث يتم اختيار طريقة الفرز لمصفوفة تحتوي على رقم 5555 و يتم عرض خطوات الفرز على الشاشة ويوضح الفرق بين عمليات الفرز السابقة
وهذه بعض من محاولات حل هذا البرنامج : ..
#include <iostream>
using namespace std;
int main()
{
int i, temp, j;
int x[] = { 88, 1, 6, 1, 2 };
cout << sizeof(x)<<endl;
for (i = 1; i < 5; i++)
{
temp = x[i];
cout << "\t temp = " << temp;
cout << "\n";
for (j = i; j>0 && x[j - 1]>temp; j--)
{
cout << "\t j-1 x[" << j - 1 << "] = " << x[j - 1];
cout << "\t temp = " << temp;
cout << "\t j x[" << j << "] = " << x[j]<<endl;
x[j] = x[j - 1];
}
cout << "\n ---------------------------- "<< endl ;
x[j] = temp;
cout << "\t temp = " << temp;
cout << "\t j x[" << j << "] = " << x[j]<<endl;
} // to print
cout << "\n order numbers= " << endl;
for (i = 0; i <= 4; i++)
cout << x[i] << "\t";
cout << "\ndone. " << endl;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i, j,temp ;
int x[5];
//= { 88, 1, 6, 1, 2,55,16,22,15,16 };
for (int t = 0; t <= 5; t++)
cin>>x[t];// << "\t";
int size =sizeof(x);
size=size/4;
//cout<<size/4<<endl;
for (i = 0; i <(size-1); i++)
{
for (j = 0; j<(size - i - 1); j++)
{
for (int t = 0; t <= (size-1); t++)
cout << x[t] << "\t";
cout<<endl;
if (x[j]>x[j + 1])
{
temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
for (int t = 0; t <= size-1; t++)
cout << x[t] << "\t";
cout<<"\n---------------------------"<<endl;
}
}
} // to print
cout << "\n order numbers= " << endl;
for (i = 0; i <= size-1; i++)
cout << x[i] << "\t";
cout << "\ndone. " << endl;
}
/*
#include <iostream>
#include <string>
using namespace std;
void main()
{
int n, i, arr[50], j, temp;
cout << "Enter total number of elements :";
cin >> n;
for (i = 0; i<n; i++)
{
cout << "Enter " << i << " numbers :";
cin >> arr[i];
}
cout << "Sorting array using bubble sort technique...\n";
for (i = 0; i<(n - 1); i++)
{
for (j = 0; j<(n - i - 1); j++)
{
if (arr[j]>arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
cout << "Elements sorted successfully..!!\n";
cout << "Sorted list in ascending order :\n";
for (i = 0; i<n; i++)
{
cout << arr[i] << " ";
}
}*/