can someone help me create a header file and main function, question asked for i
ID: 656263 • Letter: C
Question
can someone help me create a header file and main function,
question asked for integers from the keyboard in fixed-size array,array in reverse order,searches the largest number in the array and smallest.
code i got
List::List(){
for(int i=0; i<100;i++){
number[i]=0.0;
}
}
void List::input(){
string keyboard;
double digit;
int index=0;
cout<<"Enter number ";
cout<<"Enter number with a space ";
getline(cin,keyboard);
istringstream iss(keyboard);
while(iss.good()){
iss>> digit;
number[index]=digit;
index++;
}
endPoint=index;
cout<
//display back
for(int i=0;i
cout<
//reverse order
void List::reverse(int curIndex){
if(curIndex>=0){
cout<< number[curIndex]<<" ";
reverse(curIndex-1);
}
}
//largest number
void List::larNumber(int numList[],int first,int last){
if (first == last) {
cout<<"The largest number's index: "<< first< cout<<"The largest number: "<< numList[first]<
} else if (numList[first] < numList[last]) {
if(first< last){
largestNumber(numList, first + 1, last);
}else if (first>last){
largestNumber(numList, first - 1, last);
}
} else if (numList[first] > numList[last]){
int temp= first;
first= last;
last= temp;
largestNumber(numList, first, last);
}
}
//smallest number
int List::kthSmallest(int numList[], int left,int right, int k){
int i = left, j = right;
int tmp;
int pivot = numList[(left + right) / 2];
while (i <= j) {
while (numList[i] > pivot)
i++;
while (numList[j] < pivot)
j--;
if (i <= j) {
tmp = numList[i];
numList[i] = numList[j];
numList[j] = tmp;
i++;
j--;
}
};
if (left < j)
kthSmallest(numList, left, j,k);
if (i < right)
kthSmallest(numList, i, right,k);
return numList[endPoint-k];
}
Explanation / Answer
to reverse the array:
for the largest and smallest in an array:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.