某知名数据库产品公司的两道编程题(Senior QA)
1.Revert a single link list (反转一个单向链表)
2.Write a String finder function (编写一个字符串查找函数)
int StrFinder(const char* s, const char*t);
return value, if not find return -1, if find return the first match string position
(返回值,如果找不到串s中含有串t,返回-1,如果在串s中找到串t,返回第一字符在串s中的位置)
完成时间大约40分钟。
大家能不能发一下代码,看看谁能又快又好?
[解决办法]
参见stl~~~
[解决办法]
To: bargio_susie(强制结帖)
你的while循环里面:
q-> next = head-> next;
head-> next = q;
我觉得应该是:
q-> next = head;
head = q;
[解决办法]
字符串查找函数:
int StrFinder(const char *s, const char *t)
{
int i, j, k;
for (i = 0; s[i] != '\0 '; i++)
{
for(j = i, k = 0; t[k] != '\0 ' && s[j] == t[k]; j++, k++)
;
if (k > 0 && t[k] == '\0 ')
return i;
}
return -1;
}
[解决办法]
to: yangliu817(杨柳)
你再想想吧。。。
[解决办法]
s[j]可能会访问违规
[解决办法]
还是 bargio_susie写的好
[解决办法]
Link* reverse(Link* head)
{
Link* newhead=0,*node=0;
while(head)
{
node = head;
head = head-> next;
node-> next = newhead;
newhead = node;
}
return newhead;
}
[解决办法]
To:stonepeter
你自己在网上找一找吧,以前学过的,现在没精力去研究它了。
[解决办法]
同意 chenhu_doc(^0^纯一狼^0^ (国家队里,我最爱大头李玮峰!))
1.建立一个映像可以是数组,相当于修改单向链表为双向链表
不过至少要遍历一遍对于海量数据也要花不少时间
2.kmp 可惜忘得一干二净
[解决办法]
凑个热闹