السلام عليكم ورحمه الله وبركاته
أحتاج مساعدة
في إني سأستقبل من اليوز عدة ارقام
مثلا ً 9 و 3 و 1
هذي الارقام سوف أضيفها في Array موجودة لدي لكن سأرتبها تصاعدي
مثلا ً الـ Array كانت 10 , 6 , 4, 2
عند طباعتها سوف تكون
10 , 9 , 6 , 4 , 3 , 2 , 1
هذي محاولتي ....
void LinkThem( int R[ ] , int L[ ] , int Max)
{
int i, // the index of the next Request to be placed in list.
j, // the index used to find the correct place in the list.
Prevj; // the previous value of j.
L[0] = 1; // the previous value of j.
L[1] = 0; // initialize the linked list for the first request.
// R is the next request to be placed in the list
for(i = 2; i <= Max - 1; i = i + 1)
{
Prevj = 0;
// find the index j where L should point.
for(j = L[Prevj]; j != 0; j = L[j])
// R is the next request to be placed in the list
for(i = 2; i <= Max - 1; i = i + 1)
{
Prevj = 0;
// find the index j where L should point.
for(j = L[Prevj]; j != 0; j = L[j])
if(R < R[j])
{
// found the place to insert L in the list.
cout << "Inserting \n";
L[Prevj] = i;
L = j;
// get the next request to be added to the list.
}