HP官网的咳嗽居然是慢性咳嗽,百日咳# PDA - 掌中宝
j*l
1 楼
写一个stack, Push, Pop和GetMin都是O(1)时间
如果在白板上写出如下的代码,能达到面试官的基本要求么?
#define MAX_STACK_SIZE 1000
class Stack
{
int Data[MAX_STACK_SIZE];
int Link[MAX_STACK_SIZE];
int top;
public:
Stack() { top = -1; }
void Push(int x);
int Pop();
int GetMin();
};
void Stack::Push(int x)
{
if ((top + 1) == MAX_STACK_SIZE)
{
printf("Push failed, the stack is full.\n");
return;
}
int min_link = 0;
if (top > -1)
{
min_link = Link[top];
if
如果在白板上写出如下的代码,能达到面试官的基本要求么?
#define MAX_STACK_SIZE 1000
class Stack
{
int Data[MAX_STACK_SIZE];
int Link[MAX_STACK_SIZE];
int top;
public:
Stack() { top = -1; }
void Push(int x);
int Pop();
int GetMin();
};
void Stack::Push(int x)
{
if ((top + 1) == MAX_STACK_SIZE)
{
printf("Push failed, the stack is full.\n");
return;
}
int min_link = 0;
if (top > -1)
{
min_link = Link[top];
if