google搜索 51Testing站内搜索                    软件测试门户 | 软件测试培 训 | 文章资料精选 | 软件测试论坛 | 软件测试博客 | 测试招聘求职 
打印

[求助] 面试题望求教!

本主题由 ouyu 于 2008-4-30 17:38 提升

面试题望求教!


刚走出校门,今天去一家公司面试,笔试方面很顺利,但是上机题我搞不懂什么意思!
1.有一个数组arry[4,15,3,9,7,-1,55,21,9,33]十个数,请对它从小到大排序,然后输出,请注意代码的可读性(程序语言不限),排序算法自己写.
这题我写的代码如下:
/**
* 对一组无序数列进行冒泡排序。
* @author Administrator
*
*/
public class BubbleSort
{

    /**
     * 主函数入口。
     * @param args
     */
    public static void main(String args[])
    {
        int array[] = { 4,15,3,9,7,-1,55,21,9,33};
        int result[];
        //打印待排序数组。
        for (int i = 0; i < array.length; i++)
        {
            System.out.print(array + " ");
        }
        System.out.println("");
        //进行排序。
        result = bubble(array);
        //打印排序后数组。
        for (int i = 0; i < result.length; i++)
        {
            System.out.print(result + " ");
        }

    }

    /**
     * 冒泡排序。
     * @param tmp:待排序数列;
     * @return
     */
    private static int[] bubble(int tmp[])
    {
        int temp;
        for (int i = tmp.length - 1; i >= 1; i--)
        {
            for (int j = 0; j < i; j++)
            {
                if (tmp[j] > tmp[j + 1])
                {
                        //交换位置。
                    temp = tmp[j];
                    tmp[j] = tmp[j + 1];
                    tmp[j + 1] = temp;
                }
            }
        }
        return tmp;
    }
}
但是第二题我就不是很明白怎么搞了!希望高手们指点一下,并给出个答案,谢了!
2.对排序函数进行单元测试,设计一个用例.
//排序函数
//采用冒泡排序

TOP

希望大家帮帮我解决这个疑问!~谢谢了!

TOP

学长们,帮帮我啊..顶上去

TOP

你的主函数就做了单元测试啊!
预期输出: -1,3,4,7,9,9,15,21,33,55

TOP

意思是对private static int[] bubble(int tmp[])这个函数进行单元测试
设计几组tmp[]的值
拿这个代码为例
如果传入的tmp[]是null的话
取tmp的length就会exception了
“如果我当年去问顾客他们想要什么,他们肯定会告诉我‘一匹更快的马’。” -------------------亨利·福特

TOP

 
当前时区 GMT+8, 现在时间是 2008-7-6 17:35Copyright(C)上海博为峰软件技术有限公司 2001-2007 电话:021-64471599-8017
当您在访问网站、论坛及博客过程中遇到问题时可发送email:webmaster@51testing.com或发送论坛短信至管理员风在吹