0
C++
I have a sample code but I need someone who can explain me step by step this code in comment please https://drive.google.com/file/d/17268Cr9fNkwY6EXc8o-CNgTr-oFWA_MT/view?usp=drivesdk
6 Answers
0
can send the code here
0
the code is a little too long, Sololearn does not want to accept it
0
Unless I send it in two parts
0
I can't open the link
0
#include <iostream>
using namespace std;
void init(int inputSize);
int main()
{
int size;
cout << "ŠŠ²ŠµŠ“ŠøŃŠµ ŃŠ°Š·Š¼ŠµŃ Š¼Š°ŃŃŠøŠ²Š°: ";
cin >> size;
init(size);
}
void init(int inputSize)
{
int outputSize, i;
outputSize = inputSize % 2 == 0 ? inputSize * 2 : inputSize * 2 - 1;
int* input = new int[inputSize];
int* output = new int[outputSize];
int* ptr, *offsetPtr, *endPtr;
for (ptr = input, i = 0; ptr < &input[inputSize]; ptr++, i++)
{
cout << "a[" << i << "] = ";
cin >> input[i];
}
for (endPtr = &output[outputSize], ptr = input, offsetPtr = output, i = 0; ptr < &input[inputSize]; ptr++, i++)
{
if (i % 2 == 0 && i != 0)
{
offsetPtr = offsetPtr + 2;
}
*offsetPtr = *ptr;
if ((offsetPtr + 2) < endPtr)
{
*(offsetPtr+2) = *ptr;
}
offsetPtr++;
}
for (ptr = input; ptr < &input[inputSize]; ptr++)
{
cout << *ptr;
}
cout << " ā> ";
delete[] input;
for (ptr = output; ptr < &output[outputSize]; ptr++)
{
cout <<" " <<*ptr << " ";
}
delete[] output;
}
0
hereš