j**l 发帖数: 2911 | 1 面试的时候,test cases是重要的考查方面
假定有一个01字符串,用计数排序实现把所有的0放在左边,所有的1放在右边。
白板程序大致是这样
void CountSort01String(char str[])
{
if (str == NULL)
return;
int count0 = 0;
int count1 = 0;
int i;
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] == '0')
count0++;
else if (str[i] == '1')
count1++;
else
{
printf("Invalid input string.\n");
return;
}
}
int n = count0 + count1;
for (i = 0; i < c |
r****o 发帖数: 1950 | 2 多谢。请问是否thread safe怎么测呢?
【在 j**l 的大作中提到】 : 面试的时候,test cases是重要的考查方面 : 假定有一个01字符串,用计数排序实现把所有的0放在左边,所有的1放在右边。 : 白板程序大致是这样 : void CountSort01String(char str[]) : { : if (str == NULL) : return; : int count0 = 0; : int count1 = 0; : int i;
|
j**l 发帖数: 2911 | 3 具体细节没有必要在面试时候说吧
上次一个本地小公司电面,那个lead就提到如果一个函数里头用到了static的变量,就
很可能不是thread safe的
【在 r****o 的大作中提到】 : 多谢。请问是否thread safe怎么测呢?
|
f****4 发帖数: 1359 | |
z*j 发帖数: 42 | 5 very helpful. basically
safe = exception safe + thread safe? |
l******c 发帖数: 2555 | 6 did you get an offer?
Somebody asked me similliar question.
【在 j**l 的大作中提到】 : 面试的时候,test cases是重要的考查方面 : 假定有一个01字符串,用计数排序实现把所有的0放在左边,所有的1放在右边。 : 白板程序大致是这样 : void CountSort01String(char str[]) : { : if (str == NULL) : return; : int count0 = 0; : int count1 = 0; : int i;
|
r****o 发帖数: 1950 | 7 what is exception safe?
【在 z*j 的大作中提到】 : very helpful. basically : safe = exception safe + thread safe?
|
z*j 发帖数: 42 | 8 I mean input exception, hardware exception, environment exception...
basically, in c, return an error number or modify global error variable.
in c++, throw an exception or return error number.
For example: those are all exceptions:
1. 输入是空指针,也就是str == NULL
2. 输入是空串,也就是"\0"或者说str[0] == '\0'
3. 输入含有0和1以外的非法字符
4. 输入只有0,还要考虑1个,2个,还是多个0
5. 输入只有1,还要考虑1个,2个,还是多个1
6. 输入有0有1,还要考虑是0的个数多还是1的个数多还是个数相同,各种可能的排列
方式,包括原来就已经排好序的情形
7. 输入串很长,比如超过int能表示的最大整数,这时候你发现原始程序要追加对
count0, count1和n溢出的处理
8. 测有没有栈溢出或者内存泄漏 |
j**l 发帖数: 2911 | 9 Still between jobs.
Please be ready when onsite opportunities come.
【在 l******c 的大作中提到】 : did you get an offer? : Somebody asked me similliar question.
|