---
title: "amazon笔试题"
author: "vergilwang"
date: "2013-04-24T14:29:00Z"
tags: []
categories: ["互联网"]
slug: "amazon"
draft: false
lastmod: "2014-02-15T14:59:20Z"
id: 2011230
url: "https://vergilwang.iteye.com/blog/2011230"
---

1.判断一年是否为闰年的方法  
2.非递归实现exists方法

template &lt;class T&gt;  
class BinaryTree{  
protected:  
T* \_data;  
BinaryTree&lt;T&gt; * \_left;  
BinaryTree&lt;T&gt; * \_right;  
};

template &lt;class T&gt;  
class BST:public BinaryTree&lt;T&gt;{  
public:  
virtual bool exists(const T& item&gt; const;  
};

3.找到下面的bugs  
#include&lt;stdio.h&gt;  
#include&lt;malloc.h&gt;

void foo(int a ,char\*b)  
{  
b=(char \*)malloc(64);  
snprintf(b,"you are %d years old!/n",a);  
}

int main (void)  
{  
char \*f;  
foo(23,f);  
printf("%s/n",b);  
}

4.Design a subway traffic control system.What objects/classes/modules would you best use for this

purpose?Please draw diagrams and write up class definitions to better illustrate your

design.Write anything additional to clarify your design.