[LC++]Seperate an array into smallest to highest elements

Mark Phillips mark at austrics.com.au
Tue Feb 19 16:37:36 UTC 2002


Ezra Taylor wrote:
> 
> I want  to display  a[i] ....... a[middle] on one line then a[middle +1] ...... a[i-1] on the next.
> 
> In other words, a[i] to the middle of the array then the next element from the middle to the last element displayed on a seperate line.

Then you do

for (int i=0; i<=middle; ++i)
  cout<<a[i]<<' ';
cout<<endl;
for (int i=middle+1; i<N; ++i)
  cout<<a[i]<<' ';
cout<<endl;

or you could do

for (int i=0; i<N; ++i) {
  cout<<a[i];
  if (i==middle)
    cout<<'\n';
  else
    cout<<' ';
}
cout<<endl;

Cheers,

Mark.



More information about the tuxCPProgramming mailing list