两个int数组,无序要求合并为一个数组并排序不能用.net类库怎我做不出来

解决方案 »

  1.   

    不能用.net类库是什么意思?不能使用数组的方法?
      

  2.   

    哦,对了,还有去除重复数字。
    不能用.net封装的类如ArrayList之类的
      

  3.   

    楼主问的这两个题目都是比较经典的面试题了..要求合并为一个数组并排序
    ==
    这个考的是合并排序,我以后有个帖子有类似题目还有去除重复数字。
    ==
    这个是典型的键值对问题,如果能用泛型类就用Dictionary<int, int>解决,否则可以用数组解决
      

  4.   

    不能用 封装的东西 那你用工具 看.net的源码
    然后写成自己的方法不就行了么..
      

  5.   

    先学C++的话就不会在乎。net封装的东西
    因为C++或者C都是自己写 很少用到封装的东西
    简单的思路就是参考2个链表合并的例子 
      

  6.   

    我觉得就是考冒泡法和数组的基本应用 要是我做 就是定义一个数组 存放两个int数组的各项 然后冒泡排序
    别的没看出什么名堂来 感觉他不让用类库 那考的就是基本的语法、算法
      

  7.   

    #include<stdio.h>
    #define N  4//N用来限定数组a的长度
    #define M  3//M用来限定数组b的长度
    void main()
    {
        int a[N]={4,3,9,1};//定义数组a[]
        int b[M]={44,23,19};//定义数组b[]
        int ab[M+N];//数组ab[]是合并后的数组
        int i=0,j=0;
        /*********数组的组合:***************/
    while(i<N)
        {
    ab[i]=a[i];
    i++;
        }
        while((i<M+N)&&(j<M))
    {
    ab[i]=b[j];
    i++;
    j++;
    }
    /*************冒泡法排序:************/
    int x,y,temp=0;
    for(x=0;x<M+N-1;x++)
    {
    for(y=0;y<M+N-1-x;y++)
    {
    if(ab[y]<ab[y+1])
    {
    temp=ab[y];
    ab[y]=ab[y+1];
    ab[y+1]=temp;
    }
    }
    }
    /**********输出组合后的数组*********************/
    int k=0;
    while(k<M+N)
    {
    printf("%d\t",ab[k]);
    k++;
    }
    }
      

  8.   

    public int[] GetSort(int[] arr1,int[] arr2)
    {
        int len = arr1.lenth+arr2.lenth;
        int[] arr = new int[len];
        //合并两数组
        for(int i =0; i<arr1.lenth; i++)
        { 
            arr[i]=arr1[i];
        }
        for(int i=arr1.lenth;i<len;i++)
        {
            arr[i]=arr2[i];
        }
        //冒泡
        for(int i=0;i<len-1;i++)
        {
            for(int j = i+1;j<len;j++)
            {
                 if(arr[i]>arr[j])
                 {
                      int temp = arr[i];
                      arr[i] = arr[j];
                      arr[j] = temp;
                 }
            }
        }
        return arr;
    }一般逻辑啊,不知道对不对,就文本写的
      

  9.   

    很简单么,
    先创建一个数组将两个数组添加进去,然后对最后一个数组冒泡排序就可以了static void Main(string[] args)
            {
                int[] a = new int[3];
                a[0] = 3;
                a[1] = 6;
                a[2] = 2;
                int[] b = new int[3];
                b[0] = 4;
                b[1] = 1;
                b[2] = 5;            ///得出两个数组的长度
                int count = a.Length + b.Length;            int[] c = new int[count];
                for (int i = 0; i < count; i++)
                {
                    ///添加第一数组
                    if (i < a.Length)
                    {
                        c[i] = a[i];
                    }
                    ///添加第二个数组
                    else
                    {
                        c[i] = b[i - a.Length];
                    }
                }
                //排序
                for (int i = 0; i < c.Length - 1; i++)
                {
                    for (int k = 0; k < c.Length - 1 - i; k++)
                    {
                        if (c[k] > c[k + 1])
                        {
                            c[k] = c[k] + c[k + 1];
                            c[k + 1] = c[k] - c[k + 1];
                            c[k] = c[k] - c[k + 1];
                        }
                    }
                }
                //输出
                for (int i = 0; i < c.Length; i++)
                {
                    Console.WriteLine(c[i]);
                }
            }
      

  10.   

    嗯,大家都很热心,不错!
    我这也有一个,用的是插入排序,不过是C语言的,你自己将它改为C#吧
    /* 合并两个升序序列为一个新的升序序列 */#include "stdio.h"
    #define MAXSIZE 100
    void main(void)
    {
    int i,n1,n2,n3;
    int p,q;
    double arr1[MAXSIZE],arr2[MAXSIZE],tmp;
    double arr3[MAXSIZE]; printf("数组元素个数n1,n2=");
    scanf("%d%d",&n1,&n2);
    printf("数组arr1:");
    for(i=0;i<n1;i++)
    scanf("%lf",&arr1[i]);
    printf("数组arr2:");
    for(i=0;i<n2;i++)
    scanf("%lf",&arr2[i]);

    p=q=0;
    n3=0;
    while(p<n1&&q<n2)
    {
    if(arr1[p]<=arr2[q])
    {
    arr3[n3]=arr1[p];
    //n3++;
    p++;
    }
    else{
    arr3[n3]=arr2[q];
    //n3++;
    q++;
    }
    n3++;
    } if(p<n1)
    for(i=p;i<n1;i++)
    {
    arr3[n3]=arr1[i];
    n3++;
    } if(q<n2)
    for(i=q;i<n2;i++)
    {
    arr3[n3]=arr2[i];
    n3++;
    } for(i=0;i<n3;i++)
    {
    printf("%8.2lf",arr3[i]);
    if((i)%5==4) printf("\n");
    }
    printf("\n");
    }
      

  11.   

    我也在一个外包,我们这边的Lead好多拿着面试题(也多是算法),看着挺牛的,其实都不会做,拿着答案去找比较的Lead去给阅卷哎,何必这样呢,万一赶上个牛点的人估计把面试官都给问住了啊
      

  12.   

     public static int[] MergeArray(int[] a, int[] b)
            {
                if( a == null || b== null )
                    throw new NotSupportedException();
                int lena = a.Length;
                int lenb = b.Length;
                int[] c = new int[lena+lenb];
                int i, j, n;
                i = j = n = 0;
                while (i < lena && j < lenb)
                {
                    if (a[i] < b[j])
                    {
                        c[n++] = a[i++];
                    }
                    else if (a[i] > b[j])
                    {
                        c[n++] = b[j++];
                    }
                    else
                    {
                        c[n++] = a[i++];
                        c[n++] = b[j++];                    
                    }
                }
                if (i == lena)
                {
                    while (j < lenb)
                        c[n++] = b[j++];
                }
                else
                {
                    while (i < lena)
                        c[n++] = a[i++];
                }
                return c;
            }
      

  13.   

    不能用.net类库...傻瓜题目...稍微学过.net的都应该知道...int就是System.Int32,就是.net类库...有种你别用int...