编写一个函数,对于给定的一个多维数组成数组按从小到大进行排序得到一个新数组。谁能帮帮我写代码出来参考参考

解决方案 »

  1.   

    #include<stdio.h>
    #include<stdlib.h>          
    void main( void )   //文件的最后一定要加  ~ , 因为我是把这个符号作为终止符的 , 两个文本文件 的最后 都要加
    {
     FILE * fp1 = NULL , * fp2 = NULL  ;
     int  row = 0 , run_row = 0 , file2_run_row = 0 , file1_count = 0 , file2_count = 0 , i = 0 , line_count = 1 , temp_run_row = 0  ;
     char file1_name[ 20 ] = { '0' } , file2_name[ 20 ] = { '0' } , acc_file1 = '0' , acc_file2 = '0' ;
     char  * file1 = NULL , * file2 = NULL ;
     printf( "please input row :\n" ) ;                                    // 输入你想要的列 
     scanf( "%d" , & row ) ;
     printf( "please input file1_name and file2_name :\n" ) ;  //输入你要读取的文件一与文件二名 , 比如    file1.txt    file2.txt  main.c
        scanf( "%s%s" , file1_name , file2_name ) ;                   //中间一定要输入空格或者回车
     printf( "\n" ) ;
     if( NULL == ( fp1 = fopen( file1_name , "rb" ) ) )
     {
      printf( "can not open the file1\n" ) ;
      exit( 0 ) ;
     }
     if( NULL == ( fp2 = fopen( file2_name , "rb" ) ) )
     {
      printf( "can not open the file2\n" ) ;
      exit( 0 ) ;
     }
        run_row = ( row - 10 ) /2 ;
     temp_run_row = run_row ;
     file1 = ( char * )calloc( run_row  , sizeof( char ) ) ;
        file2 = ( char * )calloc( run_row  , sizeof( char ) ) ;
     file2_run_row = run_row  + 5 ;
     run_row -= 5 ;
     while( '~' != acc_file1 || '~' != acc_file2 )
     {
      if( '~' != acc_file1 )
      {
       file1_count = 0 ;
                while( '~' != ( acc_file1 = fgetc( fp1) ) )
          {
           if( '\r' == acc_file1 )
           {
             acc_file1 = fgetc( fp1)  ;
                         file1[ file1_count ]= '\0' ;                                
                         break ;
           }
                    file1[ file1_count ] = acc_file1 ;
           file1_count ++ ;
           if( 0 == file1_count % run_row  )
           {
            break ;
           }
          } 
          if( '~' == acc_file1 )
          {
                    file1[ file1_count ]= '\0' ;
          }
          printf( "%s" , file1 ) ;                                                  
          for( i = 0 ; i < temp_run_row - file1_count +10 ; i ++ )
          {
           printf( " " ) ;
          }
      }
      else
      {
       for( i = 0 ; i < temp_run_row + 10 ; i++ )
       {
        printf( " " ) ;
       }
      }
      if( '~' != acc_file2 )
      {
       file2_count = 0 ;
                while( '~' != ( acc_file2 = fgetc( fp2 ) ) )
          {
           if( '\r' == acc_file2 )
           {
                         acc_file2 = fgetc( fp2 ) ; 
                         file2[ file2_count ]= '\0' ;                               
                         break ;
           }
                    file2[ file2_count ] = acc_file2 ;
           file2_count  ++ ;
           if( 0 == file2_count % run_row )
           {
               break ; 
           }
          }
          if( '~' == acc_file2 )
          {
                    file2[ file2_count ]= '\0' ;
          }
          printf( "%s" , file2 ) ;
          for( i = 0 ; i < temp_run_row - file2_count ; i ++ )
          {
       printf( " " ) ;
          }
        }
        else
        {
         for( i = 0 ; i < temp_run_row ; i ++ )
         {
          printf( " " ) ;
         }
        }
              if(  line_count < 10 )
        {
                  printf( "       %d  " , line_count ) ;
         }
           else
           {
                  printf( "       %d " , line_count ) ;
        } 
        putchar( 10 ) ;
        line_count ++ ;
      }
        while( 1 ) ;
    }
    这个是程序···有没有更好用的呢··最精简的··
      

  2.   


    简单写了一下,学习一下
    int[][] map = new int[3][];
                map[0] = new int[]{9,7,6};
                map[1] = new int[]{8,3,5};
                map[2] = new int[]{4,1,2};            List<int> list = new List<int>();
                for (int i = 0; i < map.Length; ++i)
                {
                    list.AddRange(map[i].ToList());
                }
                list.Sort();
                list.ForEach(x => Console.Write(x));