QuickSort Warm Up 1

Complete the following function.

void swapPosNeg(ArrayList A)
{	
   // pre:  the array has been initialized   
   // post: the elements of the array have been rearranged without sorting so that all 
   //	    the negative numbers appear to the left of all the non-negative numbers

   int n = A.size( );
   int index = 0;

   while ( index < n - 1 )
   {
      if ( A.get(index) < 0 )        // skip it
         ______________;
      else if ( _____________ )  // skip it
         ______________;
      else                       // if both are out of place - swap them
      {
         ___________________;
         ___________________;
         ___________________;
      } // end of third branch
   } // end of while loop
} // end of function


Continue to:  Unit 3 / Prev / Next 
1Taken from Litvin's Workbook to Accompany C++ for You ++