- 浏览: 489636 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (672)
- 随便写写 (3)
- javascript (16)
- Java exam (58)
- JSP exam (25)
- Servlet exam (25)
- Struts exam (24)
- Spring exam (24)
- Hibernate exam (19)
- EJB exam (25)
- SOA exam (6)
- AJAX exam (25)
- Web开发 exam (25)
- 软件工程 exam (25)
- 项目管理 exam (25)
- .NET exam (23)
- ASP.NET exam (24)
- C# exam (24)
- C++ exam (25)
- C语言 exam (13)
- ASP exam (0)
- PHP exam (0)
- Ruby exam (0)
- Python exam (0)
- Delphi exam (0)
- Linux exam (0)
- UNIX exam (25)
- 数据库 exam (24)
- Oracle exam (25)
- SQL Server exam (20)
- MySQL exam (16)
- Mobile开发 exam (10)
- 嵌入式开发 exam (6)
- 网络安全 exam (0)
- 网络技术 exam (0)
- 综合技术 exam (0)
- HR面试 exam (0)
- 英语面试 exam (0)
- 外企面试 exam (0)
- 软件测试 exam (0)
- QTP exam (0)
- LoadRunner exam (0)
- 网友面经 exam (0)
- 应届生 exam (0)
- 面试指导 exam (0)
- IQ测试 exam (0)
- Flex exam (2)
- uml-ea (1)
最新评论
-
dxking100:
远光没有笔式题的说..
最新远光软件笔试题面试题内容(1) -
heming_way:
谢谢,正在复习软件工程考试呢,呵呵
《软件工程》选择题 -
梅玲达:
可以更详细点吗?
Hibernate中Criteria 和DetachedCriteria的作用是什么? -
buptjian:
学习下,试试看,谢谢啊~
Prototype如何实现页面局部定时刷新? -
bubblegum89:
这个。。。和我笔试时候做的 感觉完全不一样
最新远光软件笔试题面试题内容(3)
Q: All-time Most-Popular-Question: How to reverse a single link list? (Most companies ask!)
A: At least 2 popular/elegant ways to do this without using additional memory:
Non-Recursive & Recursive.
Tell me what’s the disadvantage of recursion? It’s damn expensive, be aware of stack overflow if the list is long.
// Non-Recursively (Most interviewers expect this sort of answer!)
Node *p = head; // h points to head of the linklist.
If( p == NULL)
return NULL;
link *h; //C++ style C programming
h = p;
if(p->next)
p = p->next;
h->next = NULL; // h is now an isolated node which will be the tail node eventually
while( p != NULL) {
link *t = p->next; //tmp node.
p->next = h;
h = p;
p = t;
}
return h; //h points to the new Head.
//-END-
// Recursively, In case you forgot.
reverse_ll(struct node ** hashref) {
struct node * first, last;
if(*hashref == NULL) return -1;
first = *hashref;
rest = first->next;
if(rest == NULL) return;
reverse_ll(&rest);
first->next->next = first; //reversion happens.
first->next = NULL;
} //-END-
Collateral Questions: Why recursion is evil?
A: Potential of Stack overflow for extensively nested recursions.
Q: How to print a link list reversely? (NetScreen, Netli, Yahoo!)
A: If Recursively:
rev_ll (Node *h) {
If(!h) return(-1) ;
else { rev_ll(h->next); print(h->data);}
}
If Non-Recursively:
Same as last Q/A: reverse the link-list then print out from the new head. Complexity: O(2*N)
//Similar question: How to reverse a string? Complexity O(N/2); exchange firstlast, 2nd2nd-to-the-last, etc…
Q: How to reverse doubly-linked list? (Akamai onsite San Mateo, CA)
A: // Basically, double linklist is easier to reverse, the only 2 things need to do are:
// tail head exchange; prev next exchange;
Node *PCurrent = pHead, *pTemp;
While(pCurrent) {
pTemp = pCurrent->next;
pCurrent->next = pCurrent->prev;
pCurrent->prev = pTemp;
pHead = pCurrent;
pCurrent = pTemp;
}
// pHead will point to the newly reversed head of the double link-list
// -END-
Q: How to insert a node into an ASCENDly sorted double link list? (Infoblox onsite)
A: // Note: the following code concerns all boundary conditions!!!
Assume we have a struct:
Struct Node {
Int data;
Node * prev;
Node *next;
};
//pHead, pCur, nn (new node), ppCur (pre-pCur)
if(pHead == NULL) return(0);
pCur = pHead;
while(pCur) {
if(pCur != pHead) {
ppCur = pCur->prev; //keep track of prev node.
}
if(pCur->data >= nn->data) {
if(pCur == pHead) { // insert at the head
pHead = nn;
nn->prev = NULL;
nn->next = pCur;
pCur->prev = nn;
} else { // insert at non head.
If(pCur->next == NULL) { // insert at the tail.
nn->next = NULL;
pCur->next = nn;
nn->prev = pCur;
} else { // insert somewhere in the middle.
nn->next = pCur;
pCur->prev = nn;
ppCur->next = nn;
nn->prev = ppCur;
}
return(pHead); // return head of double-linklist.
}
} else { // keep going!
pCur = pCur->next;
}
} // end of while()
Q: How to find a loop in a linked list (single link-list)/ Yahoo! Favorite onsite question.
A:
Node *p1, *p2, *head;
p1 = p2 = head;
do {
p1 = p1->next;
p2 = p2->next->next;
} while ( p1 != p2 && p1->next != NULL && p2->next != NULL && p2->next->next != NULL )
if ( p1->next == NULL || p2->next == NULL || p2->next->next == NULL) {
printf(“None loop found!\n”;
} else if ( p1 == p2 && p1 != NULL ) {
printf(“Loop found!\n”;
} // -END-
//Story Telling: A Yahoo! Director ever asked this question and he challenged me with this scenario: What if p1 and p2 fall into an endlessly looping hole? This imagined scenario/dilemma will NEVER happen as a simple reply! Don’t be afraid to stand off. This also propelled me to think what made one a Technical/Engineering Director? Stupidness, Arrogance or Ignorance? Maybe all.
Q: Print UNIQUE Array Element (PayPal onsite interview question) ????
A: // Assume it’s a char * array
char * unique_array(char *s, int size)
{
int i = 1, c = 1;
for(c=1; c<=size; ++c) {
if (s[c] != s[i-1]) { s[i] = s[c]; i++; }
}
s[i] = ‘\0’; //NULL terminate the string!
return(s);
} //-END-
Q: Filter out matching char in a char * array
A: //
char * filter_array(char *s, int size, char tgt) {
int i = 0, c;
for(c = 0; c<size; c++) {
if(s[c] != tgt) { s[i] = s[c]; i++; }
}
s[i] = ‘\0’;
return(s);
} –END-
Q: Implement your atoi()
A: // char *a int i;
Int len = strlen(a);
Int i = 0, j = 0, sign = 2; // 2 stands for ‘+’
If (a[0] == ‘-‘) {
sign = 1;
++j;
} else if(a[0] == ‘+’ ) {
sign = 2;
++j;
}
++j;
while(j < len) {
i = 10 * i + (a[j] – 48); // 48 = 0×30 which is ASCII ‘0’
++j;
}
//-END-
//NOTE: a-z: 0×41-5a(65-90); A-Z: 0×61-7a(97-122)
Q: Write a function that takes in a string parameter and checks to see whether or not it is an integer, and if it is then return the integer value.
A:
int str2int(const char *str)
{
int value = 0;
int sign = (str[0] == ‘-')?-1:1; // decide sign
int i = (str[0] == ‘-')?1:0; // decide starting index
char ch;
while(ch = str[i++])
{
if ((ch >= ‘0′)&&(ch <= ‘9′))
value = value*10 + (ch - ‘0′);
else
return 0; // non-integer
}
return value*sign;
} /* end of str2int()
Q: Implement your itoa() ?
A:
Solution 1: sprintf(s, “%d”, i);
Solution 2: Convert every digit to ASCII naturally and dump to char * array. Or just putchar() recursively.
Q:Print an integer using only putchar. Try doing it without using extra storage.
A: // recusion is one way. (since integer is only 16 or 32 or 64 bits long)
void putlong(long ln)
{
if (ln == 0) return;
if (ln < 0) {
putchar('-'); // print - sign first
putlong(abs(ln)); // print as positive number
return;
}
putlong(ln/10); // print higher digits,
putchar('0′ + ln%10); // print last digit(mod), ‘0′ + will convert to ASCII printable char.
} // end of putlong()
A: At least 2 popular/elegant ways to do this without using additional memory:
Non-Recursive & Recursive.
Tell me what’s the disadvantage of recursion? It’s damn expensive, be aware of stack overflow if the list is long.
// Non-Recursively (Most interviewers expect this sort of answer!)
Node *p = head; // h points to head of the linklist.
If( p == NULL)
return NULL;
link *h; //C++ style C programming
h = p;
if(p->next)
p = p->next;
h->next = NULL; // h is now an isolated node which will be the tail node eventually
while( p != NULL) {
link *t = p->next; //tmp node.
p->next = h;
h = p;
p = t;
}
return h; //h points to the new Head.
//-END-
// Recursively, In case you forgot.
reverse_ll(struct node ** hashref) {
struct node * first, last;
if(*hashref == NULL) return -1;
first = *hashref;
rest = first->next;
if(rest == NULL) return;
reverse_ll(&rest);
first->next->next = first; //reversion happens.
first->next = NULL;
} //-END-
Collateral Questions: Why recursion is evil?
A: Potential of Stack overflow for extensively nested recursions.
Q: How to print a link list reversely? (NetScreen, Netli, Yahoo!)
A: If Recursively:
rev_ll (Node *h) {
If(!h) return(-1) ;
else { rev_ll(h->next); print(h->data);}
}
If Non-Recursively:
Same as last Q/A: reverse the link-list then print out from the new head. Complexity: O(2*N)
//Similar question: How to reverse a string? Complexity O(N/2); exchange firstlast, 2nd2nd-to-the-last, etc…
Q: How to reverse doubly-linked list? (Akamai onsite San Mateo, CA)
A: // Basically, double linklist is easier to reverse, the only 2 things need to do are:
// tail head exchange; prev next exchange;
Node *PCurrent = pHead, *pTemp;
While(pCurrent) {
pTemp = pCurrent->next;
pCurrent->next = pCurrent->prev;
pCurrent->prev = pTemp;
pHead = pCurrent;
pCurrent = pTemp;
}
// pHead will point to the newly reversed head of the double link-list
// -END-
Q: How to insert a node into an ASCENDly sorted double link list? (Infoblox onsite)
A: // Note: the following code concerns all boundary conditions!!!
Assume we have a struct:
Struct Node {
Int data;
Node * prev;
Node *next;
};
//pHead, pCur, nn (new node), ppCur (pre-pCur)
if(pHead == NULL) return(0);
pCur = pHead;
while(pCur) {
if(pCur != pHead) {
ppCur = pCur->prev; //keep track of prev node.
}
if(pCur->data >= nn->data) {
if(pCur == pHead) { // insert at the head
pHead = nn;
nn->prev = NULL;
nn->next = pCur;
pCur->prev = nn;
} else { // insert at non head.
If(pCur->next == NULL) { // insert at the tail.
nn->next = NULL;
pCur->next = nn;
nn->prev = pCur;
} else { // insert somewhere in the middle.
nn->next = pCur;
pCur->prev = nn;
ppCur->next = nn;
nn->prev = ppCur;
}
return(pHead); // return head of double-linklist.
}
} else { // keep going!
pCur = pCur->next;
}
} // end of while()
Q: How to find a loop in a linked list (single link-list)/ Yahoo! Favorite onsite question.
A:
Node *p1, *p2, *head;
p1 = p2 = head;
do {
p1 = p1->next;
p2 = p2->next->next;
} while ( p1 != p2 && p1->next != NULL && p2->next != NULL && p2->next->next != NULL )
if ( p1->next == NULL || p2->next == NULL || p2->next->next == NULL) {
printf(“None loop found!\n”;
} else if ( p1 == p2 && p1 != NULL ) {
printf(“Loop found!\n”;
} // -END-
//Story Telling: A Yahoo! Director ever asked this question and he challenged me with this scenario: What if p1 and p2 fall into an endlessly looping hole? This imagined scenario/dilemma will NEVER happen as a simple reply! Don’t be afraid to stand off. This also propelled me to think what made one a Technical/Engineering Director? Stupidness, Arrogance or Ignorance? Maybe all.
Q: Print UNIQUE Array Element (PayPal onsite interview question) ????
A: // Assume it’s a char * array
char * unique_array(char *s, int size)
{
int i = 1, c = 1;
for(c=1; c<=size; ++c) {
if (s[c] != s[i-1]) { s[i] = s[c]; i++; }
}
s[i] = ‘\0’; //NULL terminate the string!
return(s);
} //-END-
Q: Filter out matching char in a char * array
A: //
char * filter_array(char *s, int size, char tgt) {
int i = 0, c;
for(c = 0; c<size; c++) {
if(s[c] != tgt) { s[i] = s[c]; i++; }
}
s[i] = ‘\0’;
return(s);
} –END-
Q: Implement your atoi()
A: // char *a int i;
Int len = strlen(a);
Int i = 0, j = 0, sign = 2; // 2 stands for ‘+’
If (a[0] == ‘-‘) {
sign = 1;
++j;
} else if(a[0] == ‘+’ ) {
sign = 2;
++j;
}
++j;
while(j < len) {
i = 10 * i + (a[j] – 48); // 48 = 0×30 which is ASCII ‘0’
++j;
}
//-END-
//NOTE: a-z: 0×41-5a(65-90); A-Z: 0×61-7a(97-122)
Q: Write a function that takes in a string parameter and checks to see whether or not it is an integer, and if it is then return the integer value.
A:
int str2int(const char *str)
{
int value = 0;
int sign = (str[0] == ‘-')?-1:1; // decide sign
int i = (str[0] == ‘-')?1:0; // decide starting index
char ch;
while(ch = str[i++])
{
if ((ch >= ‘0′)&&(ch <= ‘9′))
value = value*10 + (ch - ‘0′);
else
return 0; // non-integer
}
return value*sign;
} /* end of str2int()
Q: Implement your itoa() ?
A:
Solution 1: sprintf(s, “%d”, i);
Solution 2: Convert every digit to ASCII naturally and dump to char * array. Or just putchar() recursively.
Q:Print an integer using only putchar. Try doing it without using extra storage.
A: // recusion is one way. (since integer is only 16 or 32 or 64 bits long)
void putlong(long ln)
{
if (ln == 0) return;
if (ln < 0) {
putchar('-'); // print - sign first
putlong(abs(ln)); // print as positive number
return;
}
putlong(ln/10); // print higher digits,
putchar('0′ + ln%10); // print last digit(mod), ‘0′ + will convert to ASCII printable char.
} // end of putlong()
发表评论
-
C面试题(编程)
2010-08-12 16:46 6911) 读文件file1.txt的内容(例如):12345 ... -
求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
2010-08-12 16:46 848int GetSubString(char *strSourc ... -
、组合问题(从M个不同字符中任取N个字符的所有组合)
2010-08-12 16:46 745void find(char *source, char *r ... -
不开辟用于交换数据的临时空间,如何完成字符串的逆序
2010-08-12 16:46 1304不开辟用于交换数据的临时空间,如何完成字符串的逆序(在技术一轮 ... -
2005年11月金山笔试题
2010-08-12 16:46 5982005年11月金山笔试题。编码完成下面的处理函数。函数将字符 ... -
大整数数相乘的问题。(这是2002年在一考研班上遇到的算法题)
2010-08-12 16:46 682void Multiple(char A[], char B[ ... -
寻找迷宫的一条出路,o:通路; X:障碍
2010-08-12 16:46 820#define MAX_SIZE 8int H[4] = { ... -
分解成质因数(如435234=251*17*17*3*2,据说是华为笔试题)
2010-08-12 16:46 871void prim(int m, int n) { i ... -
实现strstr功能,即在父串中寻找子串首次出现的位置。(笔试中常让面试者实现标准库中的一些函数)
2010-08-12 16:46 1185实现strstr功能,即在父串中寻找子串首次出现的位置。(笔试 ... -
递归实现回文判断(如:abcdedbca就是回文,判断一个面试者对递归理解的简单程序)
2010-08-12 16:46 1093int find(char *str, int n) { ... -
歌德巴赫猜想。任何一个偶数都可以分解为两个素数之和。(其实这是个C二级考试的模拟试题)
2010-08-12 16:46 1101#include “stdafx.h”#include “ma ... -
求高于平均分的学生学号及成绩(学号和成绩人工输入)
2010-08-12 16:46 1249double find(int total, int n) { ...
相关推荐
algorithm and Data Structure pdf
Data structure and algorithm analysis.Data structure and algorithm analysis
Data Structure and Algorithm(高清,英文原版)
C语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件...
/algorithm/[category]/[algorithm]/[example]/data.js此文件预定义了一个显示在可视化模块中的数据变量。/algorithm/[category]/[algorithm]/[example]/code.js这个文件实现可视化和算法。可视化模块...
Algorithm-Algorithm-Data-Structure.zip,算法和数据结构,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
data structure and algorithm analysis, in java , 3rd edition
英文原版,主要以C语言为例讲解了数据结构以及编程思想等...
Algorithm-data-structure.zip,TaveJavaStudio,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
Algorithm-Data_Structure_and_Algorithms_Library.zip,C 中经典算法和数据结构的实现,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
Data Structure and Algorithm in C++ 3rd Edition, Clifford
180+ Algorithm & Data Structure Problems using C++
Algorithm-data-structure_algorithm.zip,javascript语言,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
Algorithm-Data-Structure-And-Algorithm.zip,日清,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
数据结构与算法,C描述。第二版,英文讲义PPT。 包含9章:Ch04-LISTS-STACKS-QUEUES(数据结构),Chapter3-Stacks-and-Queues,Chapter5 Binary Trees, chapter6 General trees,chapter7 Sorting,chapter8 Primary...
斯其维克的《Algorithm in C》的源代码,里边包含所有的例程、练习等…… 很棒。
英文版的数据结构与算法分析pdf(Data Structure and Algorithm Analysis),个人认为是很好的一本数据结构教材,适用于计算机专业的所有学生,只要你需要编代码,就一定可以使用这本书,希望采纳
Algorithm-data-structure-php-clanguage.zip,工作,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
Algorithm & Data Structure.md