软件面试题目

1.写一个函数,完成内存之间的拷贝。

void* mymemcpy( void *dest, const void *src, size_t count )
{
    char* pdest = static_cast<char *>( dest );
    const char* psrc = static_cast<const char*>( src );
    if( pdest>psrc && pdest<psrc +cout )
    {
        for( size_t i=count-1; i!=-1; --I )
                pdest[i] = psrc[i];
    }
    else
    {
        for( size_t i=0; i<count; ++I )
            pdest[i] = psrc[i];
    }
    return dest;
}

2.写一个函数找出一个整数数组中,第二大的数

const int MINNUMBER = -32767 ;
int find_sec_max( int data[] , int count)
{
   int maxnumber = data[0] ;
   int sec_max = MINNUMBER ;
   for ( int i = 1 ; i < count ; i++)
   {
      if ( data[i] > maxnumber )
      {
         sec_max = maxnumber ;
         maxnumber = data[i] ;
      }
      else
      {
         if ( data[i] > sec_max )
            sec_max = data[i] ;
      }
   }
   return sec_max ;
}
4 days ago, this page was being read.


Subscribe to Comments