How do i create a program to switch a iterative using one loop?

How do i create a program to switch a iterative using one loop that move element lesser than 25 to the left?



int main ()
{
srand(time(NULL));
int a [MAX];

cout << "Given the following array" << endl;
constructArray(a);
printArray(a);
cout << endl;


cout << "\nIterative swap of array";
iterative(a);
printArray(a);




}

void constructArray (int a[])
{

for (int i=0; i<MAX; i++)
a[i] = rand()%51;

}

void printArray (int a[])
{
for (int i=0; i<MAX; i++)
cout << a[i] << " ";
}

void swap(int& x, int& y)
{
int temp;
temp=x;
x=y;
y=temp;
}

void iterative (int a[])
{
int max;
max=10;
for (int i =0; i<max-1; i++)
{

if (a[i]>25)
{
swap (a[i],a[i+1]);
}

}


cout << endl;




}
closed account (z1CpDjzh)
Theres a code tage wich is [code] folllowed by [code/].
also what are you asking for specifically.
Last edited on
void iterative (int a[])
{
int max;
max=10;
for (int i =0; i<max; i++)
{
for(int k=0;i<max;i++)
{
if (a[i]>25)
{
swap (a[i],a[i+1]);
}
}
}
cout << endl;
}

Try this.I guess it'll work
Topic archived. No new replies allowed.