ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
User:Ncrosty - Wikipedia, the free encyclopedia

User:Ncrosty

From Wikipedia, the free encyclopedia


[edit] Nathan Crosty

crostyna@msu.edu


Computer Science Student at Michigan State University


[edit] Projects

/*
  N. Crosty
  "RoughCut"

  This algorithm roughly sorts lists of numerical values with reasonably
  even distrobution in order N processes.  If the list is required to be 
  sorted exactly, this Roughcut will improve performance on a successive
  sorting algorithm by reducing the number of inversions thus reducing the 
  number of required processes.


  TO DO:
  - Shorten run time to O(N)
  - Elimate the temporary vector
  - Better function for rounding "newPlace"
  - Better formula for finding the percentage
      > Efficient and accurate handling of any distrobution
      > Will require some statistics figures
      > Speed is more important than accuracy!

  BUGs:
  - Currently requires the list to begin with lowest value 0
*/


#include<iostream>
#include<vector>
#include<math.h>

using namespace std;

template <typename T> void roughCut( std::vector <T> & In );

template <typename T>
  void roughCut( vector<T> & In )
  {

    double largestVal = In[0];
    double smallestVal = In[0];
    double Percentage;
    int newPlace;

    typename vector<T>::iterator theIterator;
    vector<T> tempStorage;
    typename vector<T>::iterator newPlaceIterator; //holds the position of new data.


    //set the largest and smallest values.
    //note, smallest value is not currently in use
    for(theIterator=In.begin(); theIterator != In.end(); theIterator++)
    {
      // dereference theIterator which is equivalent to In[i]
      if( *theIterator < smallestVal ) { smallestVal = double(*theIterator); }
      if( *theIterator > largestVal ) {largestVal = double(*theIterator); }
    }

    for( theIterator=In.begin(); theIterator != In.end() ; theIterator++ )
    {
      // Only works when the list starts at zero.
      // Need a better formula, this is a huge disadvantage.
      //what happens with a 0 value?
      Percentage = ( double(*theIterator) / largestVal );
        
      if( tempStorage.empty() )
      {
        tempStorage.push_back(*theIterator);

      } else{
        //use a better function than floor to round up or down
        //set the approximate new place for our value
        newPlace = int( floor( Percentage  *  tempStorage.size() ) );  

        //the insert method needs to have an iterator pointing to where we want to insert
        //lets relate In[newPlace] to an iterator.
        newPlaceIterator = tempStorage.begin() + newPlace ;

             //insert the object in its new place according
             //to its relation to what is already there
             if( *theIterator >= *newPlaceIterator )
             {
               tempStorage.insert(newPlaceIterator, *theIterator);
             } else if( *theIterator < *newPlaceIterator ) {
                 if(newPlaceIterator > tempStorage.begin())
                 {
                   tempStorage.insert( (newPlaceIterator - 1) , *theIterator); 
                 }else { 
                   tempStorage.insert(newPlaceIterator, *theIterator);
                 }
             }
           }

    } //end of for loop

  In = tempStorage;
  }


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -