2014阿里巴巴面试总结

刚结束的一面,可能昨天笔试题目做得还行,今天中午电话我叫我1:30去面试,时间紧急,我吃完饭赶紧回宿舍小休息一会儿,然后奔赴文三路的华星时代大厦

人太多了,等到了2:20的样子终于叫我进去面试了,面试官只问了我一道题目,就是实现string类,我基本上写出了个大概,但是太挫了,基础太差了,漏洞太多,面试官指出了一些错误,但是我一直听不太清他说话,一来他说得太快,二来我听力本就不好,当我再问他刚说什么的时候他只是笑而不语了。。(以后遇到听不清面试官的话,就应该果断的大声说:“不好意思,我刚没听清您讲什么,能不能再讲一遍”,否则的话面试就会很尴尬,面试官以为你听到他说什么,但是你却由于实际上没听清而不知道该干什么,不知道怎么改程序)面试官有点看不下去了,叫我回去等消息吧,我目测已经跪在一面上了,果断的像我同学之前说的一轮游。。。

string类需要实现的函数:以常量字符串为参数的构造函数,拷贝构造函数,复制构造函数,重载+运算符,重载>运算符,嗯  大概这些

后来我自己写了下String类:主要实现里面的构造函数,拷贝构造函数,赋值构造函数,重载+运算符,重载>运算符

#include <iostream>
using namespace std;
class String
{
public:
	char *p;
	String();//默认构造函数
	String(const char *s);//以字符串为参数的构造函数
	String(const String &q);//拷贝构造函数
	String& operator=(const String &);//赋值构造函数
	String operator+(const String &);//加法运算
	bool operator >(const String &);//比较运算
};
String::String()
{
	p = NULL;
}
String::String(const char *s)
{
	if(!s)
	{
		p = NULL;
	}
	else
	{
		p = new char[strlen(s)+1];
		strcpy(p,s);
	}
}
String::String(const String &q)
{
	if(!q.p)
	{
		p = NULL;
	}
	else
	{
		p = new char[strlen(q.p)+1];
		strcpy(p,q.p);
	}
}
String& String::operator=(const String &q)
{
	if(this!=&q)
	{
		delete[] p;
		if(!q.p)
		{
			p = NULL;
		}
		else 
		{
			p = new char[strlen(q.p)+1];
			strcpy(p,q.p);
		}
	}
	return *this;
}
String String::operator+(const String &q)
{
	String newstring;
	if(!p)
		newstring = q;
	else if(!q.p)
		newstring = *this;
	else
	{
		newstring.p = new char[strlen(p)+strlen(q.p)+1];
		strcpy(newstring.p,p);
		strcat(newstring.p,q.p);
	}
	return newstring;
}
bool String::operator>(const String &q)
{
	int i=0;
	int len1 = strlen(p),len2 = strlen(q.p);
	while(i<len1&&i<len2)
	{
		if(p[i]<q.p[i])
		{
			return true;
		}
		else if(p[i]>q.p[i])
		{
			return false;
		}
		i++;
	}
	return (len1>len2)?1:0;
}
int main()
{
	String a;
	String b = "abc";
	String c = a + b;
	cout<<c.p<<endl;
	String d = c+"abc";
	bool flag = d>c;
	cout<<d.p<<endl;
	cout<<flag;
	return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值