- تاريخ التسجيل
- 14 سبتمبر 2012
- المشاركات
- 2,834
- المجموعة
- ذكر
- الدفعة الدراسية
- 2012
- الكلية
- كلية تقنية المعلومات
- التخصص
- CS - متقاعد
ممكن احد يحل لي ذي السؤال ضروري !!
Write a function named maxPosition that takes an array of integers intList, and the
The index of the last element in the array(last). The function should return the Position (Location) of the
maximum value in the array (a number between 0 and last).
For example, if the following array intList :
[TD="align: left"]25 [/TD]
[TD="align: left"] 99 [/TD]
[TD="align: left"]35 [/TD]
[TD="align: left"]40 [/TD]
[TD="align: left"]45 [/TD]
[TD="align: left"]50[/TD]
[TD="align: left"] 55 [/TD]
[TD="align: left"] 888 [/TD]
[TD="align: left"] 65[/TD]
[TD="align: left"] 70[/TD]
is called with the value of last as 9 it should return 7,
but if it is called with the value of last as 6 it should return 1.
PARTD
Use the above function of part C to write a selectionsort function to sort an array of integers in
descending order (High to low).
أظن جذي ..
كود:
#include <iostream>
using namespace std ;
int maxPosition (int list[],int last)
{
int max=0,pos=last;
for (int i=0;i<last;i++)
if(list[i]>max){max=list[i];pos=i;}
return pos;
}
void selectionsort (int list[],int size)
{
int pos,temp;
for (int i=0;i<size;i++)
{
pos=maxPosition(list,i);
if (list[pos]<list[i]){
temp=list[i];
list[i]=list[pos];
list[pos]=temp;}
}
}
int main ()
{
int arr[10]={25,99,35,40,45,50,55,888,65,70};
selectionsort(arr,10);
for(int i=0;i<10;i++)
cout<<arr[i]<<" ";
cout<<endl;
system("pause");
return 0 ;
}






, عدلت في برنامجي وصار مثل ما قلت لازم احط ال size بدل ما احطه فاضي ولازم اسوي i++ بدل i+=2