由买买提看人间百态

topics

全部话题 - 话题: struct
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
v***a
发帖数: 365
1
来自主题: JobHunting版 - 问个算法题
第一次写 c 程序,不保证正确,请自己 debug
程序假设单词是 a to z 组成
用的 bst counting, 然后 导出来 qsort
#include
#include
struct _node;
typedef struct _node {
int cc;
char c;
struct _node * n[26];
struct _node * fa;
} node;
void addToTree(node * root, node * r, const char * p1, const char * p2) {
int t;
int i;
if (p1 == p2) {
if (r->cc == 0) root->cc++;
r->cc++;
return;
}
t = (*p1) - (int)'a';
if (r->n[t] == NULL) {
r->n[t] = (node *... 阅读全帖
S**I
发帖数: 15689
2
来自主题: JobHunting版 - [合集] 收到G家拒信,发面经
☆─────────────────────────────────────☆
recursive (递归) 于 (Mon Apr 11 10:56:49 2011, 美东) 提到:
大半夜收到HR的thank you note。不用管什么NDA了
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array with repeated elements
for given element, find out its range.
e.g. A A B B B B B C C D D E F G, given B, the out... 阅读全帖
S**I
发帖数: 15689
3
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
S**I
发帖数: 15689
4
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
K*********n
发帖数: 2852
5
来自主题: JobHunting版 - 问个二叉树删除结点的问题
结点定义应该有father的吧:
typedef struct NODE(){
int val;
struct NODE *father;
struct NODE *left;
struct NODE *right;
}Node;
g**4
发帖数: 863
6
在c里面用非动态的array保存非动态的一个struct信息,为什么struct里面的信息在
declare过后不久,里面就乱了
是cs107里面的第3个作业。
以下是详细说明:
typedef struct
{
void* elems;
int elemSize;
int loglength;
int alloclength;
void (*freeFn)(void *);
} vector;
typedef struct {
vector (*arr)[];
int elemSize;
.....

} hashset;
在declare一个hashset h后,在hashsetNew(&h, ...)给里面的参数都赋了值,在
hashsetNew()里面测试参数一切正常
但是当&h被pass到另一个function里面,vector里面的参数全都乱了套
困扰好几天了,求助~~
S*******w
发帖数: 24236
7
来自主题: JobHunting版 - G电面面经
第一题:
//return the right most deepest node
int deepest (struct node * root, struct node ** result) {
struct node * deepest_l;
struct node * deepest_r;
int l, r;
if(root == NULL) {
*result = NULL;
return 0;
}
l = deepest(root->left, &deepest_l);
r = deepest(root->right, &deepest_r);
if(l > r) {
if(deepest_l != NULL) *result = deepest_l;
else *result = root;
return 1 + l;
... 阅读全帖
H**********5
发帖数: 2012
8
来自主题: JobHunting版 - 感觉今天结结实实被烙印阴了
void deleteNode(struct node *head,int data)
{
struct node *temp=NULL;
struct node *prev=head;
struct node *curr=head->next;
if(head->data==data)
{
if(head->next==NULL)
{
printf("There is only one node,can not be deletedn");
return;
}
head->data=head->next->data;
temp=head->next;
head->next=head->next->next;
free(temp);
return;
}
while(curr!=NULL)
{
if(curr->data==data)
... 阅读全帖
x****u
发帖数: 81
9
大家好,最近忙于找工作,听人介绍发现了这个版面,看了各位大大的帖子受益匪浅,
于是也来分享下自己电面的题目。几次电面发挥得很不理想,我自己总结了一些教训,
也希望大家指点迷津,给我点建议,先行谢过!
// 题目
1. Yahoo
Given a integer array, how to find the median?
Running median. Numbers keep coming in one after another, how to get the
median?
2. Google
(1)
struct A {struct A *b;}
struct A * d = 0;
void S(struct *f) {f->b = d; d=f;}
What is function S doing? Can you name this function?
What if we need S to work with any type of pointer?
Does your solution work in multi-threaded programs? Why? How... 阅读全帖
t*****d
发帖数: 525
10
来自主题: JobHunting版 - 老码农骂小码农的强文。 (转载)
【 以下文字转载自 PDA 讨论区 】
发信人: weidong (伊拉克学习小组副组长), 信区: PDA
标 题: 老码农骂小码农的强文。
发信站: BBS 未名空间站 (Mon Nov 2 19:52:49 2015, 美东)
Linus Tovalds骂瞎写代码的小码农,荡气回肠,应该下发所有码农学习。
Christ people. This is just sh*t
.The conflict I get is due to stupid new gcc header file crap. But what
makes me upset is that the crap is for completely bogus reasons.
This is the old code in net/ipv6/ip6_output.c:
mtu -= hlen + sizeof(struct frag_hdr);
and this is the new “improved” code that uses fancy stuff that wants
magical built-in... 阅读全帖
d**********o
发帖数: 1321
11
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
hw3b c-.y file
上面这一楼贴了载止hw3b deadline时我match的结果(也就是老师可以以这些不match
的ERROR为借口不给后来我补上的成绩),但是因为当时我还是没有写完,后来感恩节
期间就接着又写了一些,而且hw5是based on hw3 & hw3b的基础上(当我hw5是based
on更好的hw3的结果时,我应该可以得更多的分吧)。
hw4因为写得比较顺利,就不曾保留任何交上去作业的output,没有什么一目了然的结
果是我可以贴在这里的。原本我是想要把自己最的一次作业hw5贴出来的,但那已经是
一个完整的compiler,而且以后我还需要用自己的course project来找工作,所以一定
就不贴最终结果了。那就贴一个hw3b的c-.y文件吧,它集中的hw1、hw2、hw3、 hw3b的
结果,是我自己hw3b *.y文件的最完整版本。这些作业里面也有很多机关一一人为增加
的难度,比如那六七个IO相关的function,不仅traverse tree、build syntax tree的
时候会成为一个考点(把它们作为一个node连在syntax... 阅读全帖
d**********o
发帖数: 1321
12
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
hw3b c-.y file
上面这一楼贴了载止hw3b deadline时我match的结果(也就是老师可以以这些不match
的ERROR为借口不给后来我补上的成绩),但是因为当时我还是没有写完,后来感恩节
期间就接着又写了一些,而且hw5是based on hw3 & hw3b的基础上(当我hw5是based
on更好的hw3的结果时,我应该可以得更多的分吧)。
hw4因为写得比较顺利,就不曾保留任何交上去作业的output,没有什么一目了然的结
果是我可以贴在这里的。原本我是想要把自己最的一次作业hw5贴出来的,但那已经是
一个完整的compiler,而且以后我还需要用自己的course project来找工作,所以一定
就不贴最终结果了。那就贴一个hw3b的c-.y文件吧,它集中的hw1、hw2、hw3、 hw3b的
结果,是我自己hw3b *.y文件的最完整版本。这些作业里面也有很多机关一一人为增加
的难度,比如那六七个IO相关的function,不仅traverse tree、build syntax tree的
时候会成为一个考点(把它们作为一个node连在syntax... 阅读全帖
x****o
发帖数: 21566
13
【 以下文字转载自 Linux 讨论区 】
发信人: wjk302 (akui), 信区: Linux
标 题: 大家能帮我看一下下面的问题吗,不胜感激。
发信站: BBS 未名空间站 (Wed Feb 1 22:05:13 2012, 美东)
很冒昧的打扰大家。大家能帮我看一下下面的问题吗,不胜感激。
问题是这样的,在生产环境下
1、Suse的Linux有 /nfsmnt/work_pub/web 文件夹和 /nfsmnt/work_inwork/web
文件夹 ,它们都是NFS文件挂载
2、机器上有多个进程会读写/nfsmnt/work_pub/web 文件夹的内容
3、cron会周期性的 删除/nfsmnt/work_pub/web 文件夹下所有文件,并把/nfsmnt/
work_inwork/web 文件夹下的所有内容拷贝到前面那个文件夹中
这样,完全删除/nfsmnt/work_pub/web 文件夹下所有文件的时候就会有.nfs文件删除
不掉(上面的流程因为某些问题不方便改动)。
想咨询的问题是:我现在能不能修改一下fs/nfs/dir.c ... 阅读全帖
w****2
发帖数: 2
14
很冒昧的打扰大家。大家能帮我看一下下面的问题吗,不胜感激。
问题是这样的,在生产环境下
1、Suse的Linux有 /nfsmnt/work_pub/web 文件夹和 /nfsmnt/work_inwork/web
文件夹 ,它们都是NFS文件挂载
2、机器上有多个进程会读写/nfsmnt/work_pub/web 文件夹的内容
3、cron会周期性的 删除/nfsmnt/work_pub/web 文件夹下所有文件,并把/nfsmnt/
work_inwork/web 文件夹下的所有内容拷贝到前面那个文件夹中
这样,完全删除/nfsmnt/work_pub/web 文件夹下所有文件的时候就会有.nfs文件删除
不掉(上面的流程因为某些问题不方便改动)。
想咨询的问题是:我现在能不能修改一下fs/nfs/dir.c 中 nfs_sillyrename这个方法
,把所有.nfs文件生成到/nfsmnt/temp目录下,然后重新编译内核解决上面的问题?期
待大家的指点,先谢谢了。
下面是源代码
static int nfs_sillyrename(struct in... 阅读全帖
i**p
发帖数: 902
15
来自主题: Linux版 - Micro-SD card 驱动程序
写了一个card层的sdio驱动程序,用于读Micro-SD card。
sdio_register_driver(&my_sdio_driver) 成功返回,可是my_sdio_probe()从没被
sdio core调用(卡已插入,插拔都试过)。
请有经验的大牛指点。
static int my_sdio_probe(struct sdio_func *func,
const struct sdio_device_id *id)
{
printk(KERN_DEBUG "my_sdio_probe()");
....
return 0;
}
static const struct sdio_device_id my_sdio_ids[] = {
{ .class=SDIO_ANY_ID, .vendor=SDIO_ANY_ID, .device=SDIO_ANY_ID},
{ },
};
static struct sdio_driver my_sdio_driver = ... 阅读全帖
c*****i
发帖数: 25
16
来自主题: Programming版 - 初学C,对什么该free一直搞不明白
我知道这些问题显得都很笨。请表拍我。谢谢您的指教。
比如说下面这段code
struct a {
char *b;
int c;
};
int n, m, i;
struct a *pa = (struct a*)malloc(n, sizeof(struct a));
for(i = 0; i < n; i++) {
pa[i].b = (char*)malloc(m, sizeof(char));
}
//需要把每一个pa[i].b都free吗?
for(i = 0; i < n; i++) {
free(pa[i].b);
}
//还是只有这句就够了?
free(pa);
还有一段code: :)
char **s;
int n, m, i;
s = (char**)malloc(n, sizeof(char*));
for(i = 0; i < n; i++) {
s[i] = (char*)malloc(m, sizeof(char));
}
// 需要把每一个s[i]都free吗?
for(i = 0; i < n; i++) {
fre
m*******o
发帖数: 264
17
来自主题: Programming版 - one more interview question
Let me finish this answer:
The only different between class and struct in c++ is the default access:
public in struct and private in class.
But this question ask the different between class of java and struct in c++,
so first of all, java doesn't have struct, and in java, there is no
destructor due to the garbage collection, also no operator overloading, no multiple
inheritance in java. All parameters are passed by reference in java
D****A
发帖数: 360
18
来自主题: Programming版 - 没有经过构造函数???
exactly. 这种情况不算复制构造,因为是原始构造。
;; Function refc f10() (_Z3f10v)
refc f10() ()
{
struct refc & k.101;
struct basic_ostream > & D.29480;
struct refc & k.102;
{
struct refc k;
(void) 0;
k.101 = ;
__comp_ctor (k.101);
try
{
D.29480 = operator<< (&cout, &"k exist()"[0]);
operator<< (D.29480, endl);
return ;
}
catch
{
k.102 = ;
__comp_dtor (k.102);
}
}
}
w******g
发帖数: 67
19
来自主题: Programming版 - C & C++ mixing question
我觉得题目的意思可能是:
1. C 程序能不能调用 STL 库函数
2. 如果可以, 能不能把C程序中定义的struct 作为变量传给 STL 函数。
比如,我在C程序中定义了一个struct list(或者是array of struct), 能不能调用STL
中的标准函数(像:sort,find),把C程序中的list(或者是array of struct)作为
参数传给sort 或者 find?或者在什么情况下可以传递呢?
如果理解的不对,请指教。
r*******y
发帖数: 1081
20
来自主题: Programming版 - 一个nested class的问题
thinking in c++ 里面有关于 nested friend class的一个例子,不知道有没有帮助。
//: C05:NestFriend.cpp
// Nested friends
#include
#include // memset()
using namespace std;
const int sz = 20;
struct Holder {
private:
int a[sz];
public:
void initialize();
struct Pointer;
friend struct Pointer;
struct Pointer {
private:
Holder* h;
int* p;
public:
void initialize(Holder* h);
// Move around in ... 阅读全帖
b******n
发帖数: 1629
21
来自主题: Programming版 - 一个socket中select函数的问题
一个服务器,一个客户端,客户端向服务器中同一个socket发起20个链接,然后服务器
端定时向这20个链接发数据。客户端用select来接收数据,但每次select都返回一,并
且只有最小的那个sockfd能拿到数据,如果在fd_set的时候把最小的去掉,那就是次小
的每次能拿到数据,后面的fd-isset都通不过,谁知道是怎么回事?
vector socklist;
for (int i = 0; i < connectioncount; ++i)
{
struct sockaddr_in bk_sender_addr;
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
bk_sender_addr.sin_family = AF_INET;
bk_sender_addr.sin_port = htons(TCPBKPORT);
bk_sender_addr.sin_addr.s_addr = (inet_addr(senderip.c_str()));

if ... 阅读全帖
d****n
发帖数: 1637
22
来自主题: Programming版 - 用c怎么实现generic stack (转载)
generic C 有两类,一类是 void *, 但是有转换消耗。
另一类是 C marco,但是难debug
对于你的要求,可变的size,当然要用C marco
///file gstack.c
#define _STACK_STRUCT(STACKNAME, DATATYPE) \
typedef struct STACKNAME { \
struct STACKNAME * next;\
DATATYPE value;\
}STACKNAME##_t;
#define __STACK_POP(STACKNAME, DATATYPE ) \
void pop_##STACKNAME( STACKNAME##_t *node ) \
{ \
;\
}
#define __STACK_PUSH(STACKNAME, DATATYPE ) \
void push_##STACKNAME( STACKNAME##_t *node ) \
{ \
... 阅读全帖
i***d
发帖数: 28
23
如果一个二进制文件中存有不同类型的结构体例如:
struct A{
int a;
char b;
};
struct B{
string a;
float b;
};
struct C{
vector a;
A a;
};
...
用户知道这些结构体的数目和具体实现,但不知道这些他们在二进制文件中的排列
顺序和位置。 C++ (不用Boost)有没有什么办法可以把相同结构体(比如struct A)从
二进制文件 提取出来啊? 谢谢!
d****i
发帖数: 4809
24
违法了1啊,比如C里面你声明一个struct在.h文件里面,你可以直接initialize给
struct里面的变量赋值吗?头文件里面的struct就是一个声明, .c文件里面才创建
struct的实例。
d****i
发帖数: 4809
25
C里面不是必要的话尽量不要malloc吧,比如你的例子可以简单写成:
typedef struct steque steque_t;
steque_t stq;
int i;
struct steque_item item[10];
for(i = 0; i < 10; i++)
{
steque_enqueue(&stq, &item[i]);
}
假设你的steque_enqueue函数的signature是
void steque_enqueue(struct steque_t *, struct steque_item *);
注意typedef的顺序是:
typedef existing_type new_type_name;
i**p
发帖数: 902
26
来自主题: Programming版 - Micro-SD card 驱动程序 (转载)
【 以下文字转载自 Linux 讨论区 】
发信人: isup (No), 信区: Linux
标 题: Micro-SD card 驱动程序
发信站: BBS 未名空间站 (Fri Jun 20 12:48:55 2014, 美东)
写了一个card层的sdio驱动程序,用于读Micro-SD card。
sdio_register_driver(&my_sdio_driver) 成功返回,可是my_sdio_probe()从没被
sdio core调用(卡已插入,插拔都试过)。
请有经验的大牛指点。
static int my_sdio_probe(struct sdio_func *func,
const struct sdio_device_id *id)
{
printk(KERN_DEBUG "my_sdio_probe()");
....
return 0;
}
static const struct sdio_device_id my_sdio_ids[] = {
{ ... 阅读全帖
t**r
发帖数: 3428
27
来自主题: Programming版 - 问个c++问题
你必須去改那個類,
for your reference:
#include
#include
struct A {
std::string s;
A() : s("test") {}
A(const A& o) : s(o.s) { std::cout << "move failed!n";}
A(A&& o) : s(std::move(o.s)) {}
};
A f(A a) {
return a;
}
struct B : A {
std::string s2;
int n;
// implicit move contructor B::(B&&)
// calls A's move constructor
// calls s2's move constructor
// and makes a bitwise copy of n
};
struct C : B {
~C() {}; // destructor prevents ... 阅读全帖
a*********a
发帖数: 3656
28
来自主题: Programming版 - 如何动态定义类和方法
FWIW, tested today at work that this works on a recent gcc. pretty poor
style, mem management and safety are disregarded, just a demo. but the core
of it is only about 20 lines of code.
you still have to add new shapes to that vector, but I assume if you have a
system that everything derives from a grandpa Object class, then it is
easier to do such a thing as language support. OTOH, at no point does one
have to spell out any class names except at the use site.
there is no way to call a member by... 阅读全帖
d****i
发帖数: 4809
29
Using a file to convert back and forth is a waste. You can simply use a
pointer to your struct data to do the transfer. But bear in mind that the
way you wrote may cause issue mainly due to two reasons:
1. Compiler can do some padding to struct
2. Endianess issue (big/little endian)
So in order to make it correct during network transmission, you first want
to make sure that compiler padding is removed, so you can use #pramga
directive:
#pragma pack(1)
struct packed_struct {
unsigned int f1:8... 阅读全帖
n*********m
发帖数: 38
30
Look his publication
Conversion of D-ribulose 5-phosphate to D-xylulose 5-phosphate: new insights
from structural and biochemical studies on human RPE.
Liang W, Ouyang S, Shaw N, Joachimiak A, Zhang R, Liu ZJ.
FASEB J. 2011 Feb;25(2):497-504. Epub 2010 Oct 5.
PMID:
20923965
[PubMed - indexed for MEDLINE]
Related citations
2.
Structural basis for the inhibition of human 5,10-methenyltetrahydrofolate
synthetase by N10-substituted folate analogues.
Wu D, Li Y, Song G, Cheng C, Zhang R, Joac... 阅读全帖
g**4
发帖数: 863
31
【 以下文字转载自 JobHunting 讨论区 】
发信人: gs04 (工工), 信区: JobHunting
标 题: 知道这里计算机的大牛多,问个题目~
发信站: BBS 未名空间站 (Tue Jul 24 21:35:51 2012, 美东)
在c里面用非动态的array保存非动态的一个struct信息,为什么struct里面的信息在
declare过后不久,里面就乱了
是cs107里面的第3个作业。
以下是详细说明:
typedef struct
{
void* elems;
int elemSize;
int loglength;
int alloclength;
void (*freeFn)(void *);
} vector;
typedef struct {
vector (*arr)[];
int elemSize;
.....

} hashset;
在declare一个hashset h后,在hashsetNew(&h, ...)给里面的参数都赋了值,在
hashsetNew()里面测试参数一切正常
但是当&h被pass到另一个... 阅读全帖
w******g
发帖数: 67
32
来自主题: Quant版 - question about C/C++ mixing
我觉得题目的意思可能是:
1. C 程序能不能调用 STL 库函数
2. 如果可以, 能不能把C程序中定义的struct 作为变量传给 STL 函数。
比如,我在C程序中定义了一个struct list(或者是array of struct), 能不能调用STL
中的标准函数(像:sort,find),把C程序中的list(或者是array of struct)作为
参数传给sort 或者 find?或者在什么情况下可以传递呢?
如果理解的不对,请指教。
r********n
发帖数: 7441
33
发信人: conti (conti), 信区: TsinghuaCent
标 题: zz pk饶毅进入第二轮的张旭的背景
发信站: 水木社区 (Sun Aug 28 15:38:09 2011), 站内
如果神经方向就只能上一个候选人,那么张旭入选还真是一点也不出格
发信人: WeiLiao (WeiLiao), 信区: Biology
标 题: 张旭的publications
发信站: BBS 未名空间站 (Sun Aug 28 01:39:20 2011, 美东)
去查了一下,张旭总共发表了90多篇英文文章(不算中文)。回国之后作为联系作者也
有快20篇了。其中有cell, neuron, Journal of neuroscience, PNAS 好多篇。
而且他
1995年就回国了,那个时候国内的环境有多差不用说了吧。这也快20年了。比饶益
2007
年才全职回去多了12年。比起培养的中国学生也多多了,算国内贡献肯定不会小。如果
他一直留在国外,成就未必就比饶差。谁把饶益的文章列一列。国内多少篇,总共多少
篇,培养了多少中国学生?
1. Li KC, Wang F, ... 阅读全帖
l****g
发帖数: 5080
34
来自主题: Automobile版 - 请教:修车子前面的减震装置
前面的struct换起来比后面的shock困难多了,至少对DIY来说是这样。个人来讲后面的
shock如果修车铺要超过100刀,我会自己换。前面的struct如果要价低于600刀,我让
车铺换。
这个struct如果20万mile以前需要更换,我会避免买这样的车,考虑到更换的费用,这
个应该做得和车寿命相当才好。
s****t
发帖数: 36
35
来自主题: JobHunting版 - G公司电面两轮
那个copy random pointer linklist的, 大家看看对不对啊?O(3N)~~ O(N)吧
/*
A contain data, next pointer, and random pointer, copy the A structure in
B
*/
struct node{
int data;
struct node* next;
struct node* random;
node(int value, node* n, node* r){
data = value;
next = n;
random = r;
}
}*llist;
void copyrandompointerlist(llist src, llist& dst){
// assume the first node doesn't use.
// src is the head pointer of A,
assert(src != NULL);
llist src_index, dst_index, temp;
src_in
K******g
发帖数: 1870
36
我选的C,如果被要求写一个graph的拷贝题,要写代码,请问我下面的代码可不可以。
是太简略了呢,还是没有必要这么详细定义结构体,请有经验的人指教。多谢了!
Typedef struct T_vertext
{
Int data;
Int color;
Int d;
LIST *adj;
} VERTEX;
Typedef struct T_list
{
VERTEX* v;
Struct T_list *next;
} LIST;
VERTEX *G1; /*assume it has been already initialized to includes all vertex
in G1*/
VERTEX *G2; //the new graph that is going to be created.
QUEUE q;
For each vertex in G1:
{
Vertex.color = WHITE;
Vertex.d = 0;
}
S = G1.getVertex(0);
Enqueue(q, s);
x****k
发帖数: 2932
37
来自主题: JobHunting版 - Apple的一些C++概念题
A general template:
template struct X
{ void f() { cout << "Primary template" << endl; } };
Partial specialized template(only for template class and struct, not for
funtion)
template struct X
{ void f() { cout << "Partial specialization 1" << endl;
} };
l**o
发帖数: 356
38
来自主题: JobHunting版 - 说说下午的面试经历。。。
是一家号称很大很大的公司,做software engineer
本来是有两个部门的,hr领我去见第一个部门的人,结果那个人说我一个小时前发邮件
给你,你没看到吗?我们要senior的, 我今天下午没空,然后就会自己的cube去了。
。。任凭hr在旁边说人大老远来的,又是火车又是出租的。。。
还好还有第二个部门。
先是HM,是个印度人,让我介绍以前做的东西和嵌入式的内容,还问我1'compliment 2
'compliment.
再写了程序:
for(i = 0; i != 100; ++i){
printf(...);
}
问我printf执行多少遍,我先帮他确定i 是整数,然后回答100,他说不是,让我回去
试。。。争执许久,未果
第二个是个黑哥们,握手的时候跟你轻轻一碰,弄得我真不好意思呀,想要占人便宜似
的。我简历上最近的,和这份工作最相关的内容不问,打破砂锅问我四年前做过的东西
。我但凡回答什么,他都okokokokok,头从上到下这么转一圈。然后问我,定义两个
struct,怎么copy...不是同一个struct的不同对象,是两个struct。。。
第三个人问得挺正常的,... 阅读全帖
d******a
发帖数: 238
39
来自主题: JobHunting版 - MS onsite 面经
some of them might be easy to give out idea, but a little hard to write bug-
free code.
1 merge-sort without recursion
we should use loop to sovle it. we could use loop to get n/2 sorted
subarrays, then n/4 sorted arrays...I think we should be careful to consider
the boundary conditions.
2 Find whether one string is a subset of another string (not need to be
contiguous, but order should match).
use the idea of hash, > is a pair. e.g. "abcaeaf", "aaf"
a 0, 3, 5
b 1,
c 2,
e 4... 阅读全帖
s********k
发帖数: 6180
40
来自主题: JobHunting版 - One question about Void pointer (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: silverhawk (silverhawk), 信区: Programming
标 题: One question about Void pointer
发信站: BBS 未名空间站 (Mon Mar 28 10:32:50 2011, 美东)
Is it risk to use void pointer in the following case:
typedef struct
{
void *next;
UINT16 xx;
UINT16 yy;
byte zz;
} a;
mostly, I think
struct a
{
struct a *next;
UINT16 xx;
UINT16 yy;
byte zz;
};
could be better, but is there any risk to use void pointer? what we should
pay attention in order to carefully manipulate the poin... 阅读全帖
c********2
发帖数: 56
41
来自主题: JobHunting版 - 贴个FLEXTRADE的在线C++测试的题
面的是Associate C++ Developer,下面是面试题,光顾着记题了,最后只有56%的通过
率,要到
80%才能ONSITE,算是帮大家做点贡献吧,他家在招人,赶快去投简历
1) #include
using namespace std;
struct A{
A(int value) : m_value(value){}
int m_value;
};
struct B:A {
B(int value):A(value){}
};
int main(){
try {
try{
throw B(5);
}
catch(A a){
a.m_value *=2;
throw;
}
catch(B b){
b.m_value -=2;
throw b;
}
}
catch(A a){
... 阅读全帖
f**********t
发帖数: 1001
42
来自主题: JobHunting版 - 问一道Amazon题,觉得很诡异
道听途说的,觉得该题好诡异。
一个struct, 含{id, string}。现有100万个该struct元素。
每个id 10bit, 每个string保证能Load到memory,大小不定。
有没有O(1)空间,O(n)时间的算法?
O(1)空间指不管输入多少个struct元素,都是固定内存。
k***t
发帖数: 276
43
来自主题: JobHunting版 - Facebook电面题目
本人一直只写C,看过一点STL。欢迎大家 Code Review。谢谢。
觉得has_next_level flag 部分不够简单明了,但没有它不好
在输出中换行和终止加dummy node.
#include
using namespace std;
typedef struct TreeNode_ {
int value;
struct TreeNode_ *left;
struct TreeNode_ *right;
} TreeNode;
int level (TreeNode *root) {
queue Q;
TreeNode *cur, dummy;
bool has_next_level;

if (!root) return -1;
Q.push(root); Q.push(&dummy);
has_next_level = false;

while(!Q.empty()) {
cur = Q.front();
... 阅读全帖
d********w
发帖数: 363
44
来自主题: JobHunting版 - c语言实现TreeFee
Given a binary tree made up out of the following structures:
typedef struct _tnode {
int key;
struct _tnode *left;
struct _tnode *right;
void *datum;
} TreeNode;
Write a C routine with the following prototype that returns all TreeNodes of
a tree to free
store:
void TreeFree(TreeNode *root,void (*datafreer)(void *));
where root is the root node of a tree, and datafreer is a pointer to a
function returning
void and taking a void * that will return the object pointed to by a
TreeNode.datum
pointer ... 阅读全帖
q****x
发帖数: 7404
45
来自主题: JobHunting版 - 讨论一个OO问题
struct Message {
virtual ~Message() = 0;
explicit Message(const string name&):name_(name);
void f() { cout << name_ << "order executed" << endl; }
string name_;
};
Message::~Message() {}
struct BuyMessage: public Message {
BuyMessage(): Message("Buy");
};
struct SellMessage: public Message {
SellMessage(): Message("Sell");
};
这里所有数据都可以在Message里处理。Buy和SellMessage的区别就是给name_赋不同的
值。
这种继承符合OO原理吗?
l****c
发帖数: 782
46
新手我试一下哈
typedef struct Node{
int value;
int level;
struct Node *left;
struct Node *right;
} node;
void_print(int LEVEL)
{
node *root;
if (LEVEL==0) return;
node *tmp = root;
queue.push(tmp);
stack.push(tmp);
while (queue.front()->level < LEVEL) {
int tmp_level = queue.front()->level;
while(queue.front()->level==tmp_level) {
node *tmp = queue.pop_front();
queue.push_back(tmp->left);
queue.push_back(tmp->right);
stack.push_back(tmp->left);
stack.push_back(tmp->right);
}
}
while(!stack.is... 阅读全帖
a*******y
发帖数: 1040
47
来自主题: JobHunting版 - 那个skiplist的题谁来给谢谢
写code实现struct skip_list * find(struct skip_list *head, int value)
还有这个struct怎么定义?
c********s
发帖数: 817
48
来自主题: JobHunting版 - MathWorks Interview 求祝福!
> Bless.
> 我也下周一要电话聊聊。不知道具体是什么。职位是关于stateflow。
已经聊过了。45分钟。前三十五分钟讲自己PhD的projects。最后几分钟问了一些C++的
概念题。(为什么要用pointer。stack和heap的不同。class和struct的不同。为什么
要用struct。对于class,哪些methods由compiler默认生成。struct也有相关的默认生
成的methods吗。)还根据我所讲的问了一些别的。什么是binary tree. 什么是
asymptotic complexity.
等了差不多一周才开始schedule 下一轮。
谢谢祝福!
c********s
发帖数: 817
49
来自主题: JobHunting版 - MathWorks Interview 求祝福!
> Bless.
> 我也下周一要电话聊聊。不知道具体是什么。职位是关于stateflow。
已经聊过了。45分钟。前三十五分钟讲自己PhD的projects。最后几分钟问了一些C++的
概念题。(为什么要用pointer。stack和heap的不同。class和struct的不同。为什么
要用struct。对于class,哪些methods由compiler默认生成。struct也有相关的默认生
成的methods吗。)还根据我所讲的问了一些别的。什么是binary tree. 什么是
asymptotic complexity.
等了差不多一周才开始schedule 下一轮。
谢谢祝福!
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)