When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
12 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
!f
#include <iostream>
using namespace std;
int* insertion_sort(int* arr, int size) {
int j;
int k;
for (int i = 1; i < size; i++) {
k = arr[i];
j = i - 1;
while (j >= 0 && arr[j] > k) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = k;
}
return arr;
}
void even_odd(int* arr, int size) {
int arr2[100]; // creating new array
// sorting array
int* arr1 = insertion_sort(arr, size);
// i points from left and j from right
int i = 0;
int j = size - 1;
int k = 0;
while (i <= j) // exit when i exceed j
{
// insert a[i] if k is even k = 0 , 2 , 4 , 6 ...
if (k % 2 == 0) {
arr2[k] = arr1[i];
i++;
}
// insert a[j] if k is odd k = 1 , 3, 5 , 7 ....
else {
arr2[k] = arr1[j];
j--;
}
k++; // k increment by 1 ,from 0 to size-1
}
for (int i = 0; i < size; i++) {
cout << arr2[i] << " ";
}
}
int main() {
int rep;
cin >> rep;
while (rep != 0) {
int arr[100];
int size;
cin >> size;
for (int i = 0; i < size; i++) {
cin >> arr[i];
}
even_odd(arr, size);
rep--;
cout << endl;
}
}
#1013107104678162544
Can't you read?
sorry what
.
i didnt get you
This is #1013104018739974194 .
You're not programming in C.
You're programming in C++.
You need to go to #1013107104678162544.
ok sorry
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.