剑指offer完整版PDF带目录源码C++和Java版


剑指offer完整版PDF带目录源码(C++和Java版)
资源截图
代码片段和文件信息
// Accumulate.cpp : Defines the entry point for the console application.
//

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

#include “stdafx.h“

// ====================方法一====================
class Temp
{
public:
    Temp() { ++ N; Sum += N; }

    static void Reset() { N = 0; Sum = 0; }
    static unsigned int GetSum() { return Sum; }

private:
    static unsigned int N;
    static unsigned int Sum;
};

unsigned int Temp::N = 0;
unsigned int Temp::Sum = 0;

unsigned int Sum_Solution1(unsigned int n)
{
    Temp::Reset();

    Temp *a = new Temp[n];
    delete []a;
    a = NULL;

    return Temp::GetSum();
}

// ====================方法二====================
class A;
A* Array[2];

class A
{
public:
    virtual unsigned int Sum (unsigned int n) 
    { 
        return 0; 
    }
};

class B: public A
{
public:
    virtual unsigned int Sum (unsigned int n) 
    { 
        return Array[!!n]->Sum(n-1) + n; 
    }
};

int Sum_Solution2(int n)
{
    A a;
    B b;
    Array[0] = &a;
    Array[1] = &b;

    int value = Array[1]->Sum(n);

    return value;
}

// ====================方法三====================
typedef unsigned int (*fun)(unsigned int);

unsigned int Solution3_Teminator(unsigned int n) 
{
    return 0;
}

unsigned int Sum_Solution3(unsigned int n)
{
    static fun f[2] = {Solution3_Teminator Sum_Solution3}; 
    return n + f[!!n](n - 1);
}

// ====================方法四====================
template  struct Sum_Solution4
{
    enum Value { N = Sum_Solution4::N + n};
};

template <> struct Sum_Solution4<1>
{
    enum Value { N = 1};
};

template <> struct Sum_Solution4<0>
{
    enum Value { N = 0};
};

// ====================测试代码====================
void Test(int n int expected)
{
    printf(“Test for %d begins:
“ n);

    if(Sum_Solution1(n) == expected)
        printf(“Solution1 passed.
“);
    else
        printf(“Solution1 failed.
“);

    if(Sum_Solution2(n) == expected)
        printf(“Solution2 passed.
“);
    else
        printf(“Solution2 failed.
“);

    if(Sum_Solution3(n) == expected)
        printf(“Solution3 passed.
“);
    else
        printf(“Solution3 failed.
“);
}

void Test1()
{
    const unsigned int number = 1;
    int expected = 1;
    Test(number expected);
    if(Sum_Solution4::N == expected)
        printf(“Solution4 passed.
“);
    else
        printf(“Solution4 failed.
“);
}

void Test2()
{
    const unsigned int number = 5;
    int expected = 15;
    Test(number expected);
    if(Sum_Solution4::N == expected)
        printf(“Solution4 passed.
“);
    else
        printf(“Solution4 failed.
“);
}

void Test3()
{
    const unsigned int number = 10;
    int expected = 55;
    Test(number expected);
    if(Sum_Solution4::N == expected)
        printf(“Solution4 passed.
“);
    else
        printf(“Solution4 failed.
“);
}

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

     文件     157184  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestions.vsInterviewQuestionsv14.suo

     文件       3414  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulateAccumulate.cpp

     文件       4528  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulateAccumulate.vcproj

     文件       1417  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulateAccumulate.vcproj.HAIHE-WIN7.Harry He.user

     文件       5169  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulateAccumulate.vcxproj

     文件       1321  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulateAccumulate.vcxproj.filters

     文件       1320  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulateReadMe.txt

     文件        297  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulatestdafx.cpp

     文件        320  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulatestdafx.h

     文件        765  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAccumulate argetver.h

     文件        932  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbersAddTwoNumbers.cpp

     文件       4537  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbersAddTwoNumbers.vcproj

     文件       1417  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbersAddTwoNumbers.vcproj.HAIHE-WIN7.Harry He.user

     文件       5178  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbersAddTwoNumbers.vcxproj

     文件       1324  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbersAddTwoNumbers.vcxproj.filters

     文件       1338  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbersReadMe.txt

     文件        300  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbersstdafx.cpp

     文件        320  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbersstdafx.h

     文件        765  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAddTwoNumbers argetver.h

     文件       2455  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperatorAssignmentOperator.cpp

     文件       4552  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperatorAssignmentOperator.vcproj

     文件       1417  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperatorAssignmentOperator.vcproj.HAIHE-WIN7.Harry He.user

     文件       5193  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperatorAssignmentOperator.vcxproj

     文件       1329  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperatorAssignmentOperator.vcxproj.filters

     文件       1368  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperatorReadMe.txt

     文件        305  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperatorstdafx.cpp

     文件        320  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperatorstdafx.h

     文件        765  2017-10-10 21:46  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsAssignmentOperator argetver.h

     文件      58013  2017-10-10 21:47  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsBackupInterviewQuestions.sln

     文件     158208  2017-10-10 21:47  剑指offer完整版带目录源码(C++和Java版)InterviewQuestionsBackupInterviewQuestions.v12.suo

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

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

发表评论

评论列表(条)