剑指offer源码及测试用例


快来下载啊,只需要1积分!!!这个是剑指offer的源码,挺全的,还有具体的测试用例~
资源截图
代码片段和文件信息
// NumberOf1InBinary.cpp : Defines the entry point for the console application.
//

// 《剑指Offer——名企面试官精讲典型编程题》代码
// 著作权所有者:何海涛

#include “stdafx.h“

int NumberOf1_Solution1(int n)
{
    int count = 0;
    unsigned int flag = 1;
    while(flag)
    {
        if(n & flag)
            count ++;

        flag = flag << 1;
    }

    return count;
}

int NumberOf1_Solution2(int n)
{
    int count = 0;

    while (n)
    {
        ++ count;
        n = (n - 1) & n;
    }

    return count;
}

void Test(int number unsigned int expected)
{
    int actual = NumberOf1_Solution1(number);
    if(actual == expected)
        printf(“Solution1: Test for %p passed.
“ number);
    else
        printf(“Solution1: Test for %p failed.
“ number);

    actual = NumberOf1_Solution2(number);
    if(actual == expected)
        printf(“Solution2: Test for %p passed.
“ number);
    else
        printf(“Solution2: Test for %p failed.
“ number);

    printf(“
“);
}

int _tmain(int argc _TCHAR* argv[])
{
    // 输入0,期待的输出是0
    Test(0 0);

    // 输入1,期待的输出是1
    Test(1 1);

    // 输入10,期待的输出是2
    Test(10 2);

    // 输入0x7FFFFFFF,期待的输出是31
    Test(0x7FFFFFFF 31);

    // 输入0xFFFFFFFF(负数),期待的输出是32
    Test(0xFFFFFFFF 32);

    // 输入0x80000000(负数),期待的输出是1
    Test(0x80000000 1);

    return 0;
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1470  2011-09-30 15:25  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions10NumberOf1InBinaryNumberOf1InBinary.cpp

     文件       4549  2011-06-20 17:29  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions10NumberOf1InBinaryNumberOf1InBinary.vcproj

     文件       1417  2011-10-24 11:50  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions10NumberOf1InBinaryNumberOf1InBinary.vcproj.HAIHE-WIN7.Harry He.user

     文件       1427  2015-09-08 18:48  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions10NumberOf1InBinaryNumberOf1InBinary.vcproj.USER-20150421XR.Administrator.user

     文件       1362  2011-02-05 08:23  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions10NumberOf1InBinaryReadMe.txt

     文件        304  2011-02-05 08:23  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions10NumberOf1InBinarystdafx.cpp

     文件        320  2011-02-05 08:23  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions10NumberOf1InBinarystdafx.h

     文件        765  2011-02-05 08:23  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions10NumberOf1InBinary argetver.h

     文件       2553  2011-10-24 11:48  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions11PowerPower.cpp

     文件       4513  2011-06-08 17:26  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions11PowerPower.vcproj

     文件       1417  2011-10-24 11:50  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions11PowerPower.vcproj.HAIHE-WIN7.Harry He.user

     文件       1427  2015-09-08 18:48  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions11PowerPower.vcproj.USER-20150421XR.Administrator.user

     文件       1290  2011-03-16 09:58  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions11PowerReadMe.txt

     文件        292  2011-03-16 09:58  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions11Powerstdafx.cpp

     文件        320  2011-03-16 09:58  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions11Powerstdafx.h

     文件        765  2011-03-16 09:58  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions11Power argetver.h

     文件       2968  2011-09-30 15:25  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions12Print1ToMaxOfNDigitsPrint1ToMaxOfNDigits.cpp

     文件       4558  2011-06-08 17:26  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions12Print1ToMaxOfNDigitsPrint1ToMaxOfNDigits.vcproj

     文件       1417  2011-10-24 11:50  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions12Print1ToMaxOfNDigitsPrint1ToMaxOfNDigits.vcproj.HAIHE-WIN7.Harry He.user

     文件       1427  2015-09-08 18:48  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions12Print1ToMaxOfNDigitsPrint1ToMaxOfNDigits.vcproj.USER-20150421XR.Administrator.user

     文件       1380  2011-03-19 22:42  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions12Print1ToMaxOfNDigitsReadMe.txt

     文件        307  2011-03-19 22:42  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions12Print1ToMaxOfNDigitsstdafx.cpp

     文件        320  2011-03-19 22:42  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions12Print1ToMaxOfNDigitsstdafx.h

     文件        765  2011-03-19 22:42  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions12Print1ToMaxOfNDigits argetver.h

     文件       3277  2011-09-30 15:25  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions13DeleteNodeInListDeleteNodeInList.cpp

     文件       4546  2011-06-20 17:29  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions13DeleteNodeInListDeleteNodeInList.vcproj

     文件       1417  2011-10-24 11:50  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions13DeleteNodeInListDeleteNodeInList.vcproj.HAIHE-WIN7.Harry He.user

     文件       1427  2015-09-08 18:48  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions13DeleteNodeInListDeleteNodeInList.vcproj.USER-20150421XR.Administrator.user

     文件       1356  2011-03-27 23:09  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions13DeleteNodeInListReadMe.txt

     文件        303  2011-03-27 23:09  剑指offer源码及测试用例剑指offer源码及测试用例InterviewQuestions13DeleteNodeInListstdafx.cpp

............此处省略518个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)