- 浏览: 507434 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (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 7191) 读文件file1.txt的内容(例如):12345 ... -
求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
2010-08-12 16:46 879int GetSubString(char *strSourc ... -
、组合问题(从M个不同字符中任取N个字符的所有组合)
2010-08-12 16:46 770void find(char *source, char *r ... -
不开辟用于交换数据的临时空间,如何完成字符串的逆序
2010-08-12 16:46 1334不开辟用于交换数据的临时空间,如何完成字符串的逆序(在技术一轮 ... -
2005年11月金山笔试题
2010-08-12 16:46 6292005年11月金山笔试题。编码完成下面的处理函数。函数将字符 ... -
大整数数相乘的问题。(这是2002年在一考研班上遇到的算法题)
2010-08-12 16:46 716void Multiple(char A[], char B[ ... -
寻找迷宫的一条出路,o:通路; X:障碍
2010-08-12 16:46 849#define MAX_SIZE 8int H[4] = { ... -
分解成质因数(如435234=251*17*17*3*2,据说是华为笔试题)
2010-08-12 16:46 890void prim(int m, int n) { i ... -
实现strstr功能,即在父串中寻找子串首次出现的位置。(笔试中常让面试者实现标准库中的一些函数)
2010-08-12 16:46 1207实现strstr功能,即在父串中寻找子串首次出现的位置。(笔试 ... -
递归实现回文判断(如:abcdedbca就是回文,判断一个面试者对递归理解的简单程序)
2010-08-12 16:46 1134int find(char *str, int n) { ... -
歌德巴赫猜想。任何一个偶数都可以分解为两个素数之和。(其实这是个C二级考试的模拟试题)
2010-08-12 16:46 1130#include “stdafx.h”#include “ma ... -
求高于平均分的学生学号及成绩(学号和成绩人工输入)
2010-08-12 16:46 1273double find(int total, int n) { ...
相关推荐
这个压缩包包含了《Data Structure and Algorithm Analysis in C》一书的习题答案,虽然它不是教材本身,但可以作为学习过程中的宝贵参考资料。 数据结构主要包括数组、链表、栈、队列、树(如二叉树、AVL树、红黑...
/algorithm/[category]/[algorithm]/[example]/data.js此文件预定义了一个显示在可视化模块中的数据变量。/algorithm/[category]/[algorithm]/[example]/code.js这个文件实现可视化和算法。可视化模块...
C语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件 algorithmC语言头文件...
"Algorithm-data-structure.zip"这个压缩包,显然聚焦于这两个关键概念,尤其针对数据结构部分,它包含了"data-structure-master"这一子文件夹,预示着我们将深入探讨数据结构的各种实现和应用。 算法,简单来说,...
在"Algorithm-data-structure_algorithm.zip"这个压缩包中,我们可以推测其内容可能包含了使用JavaScript语言实现的各种算法和数据结构。 首先,让我们深入了解一下算法。算法可以分为不同的复杂度类别,如线性、...
1. 数据结构与算法的基础概念 - 《数据结构与算法》一书是专门讲述数据结构与算法的专业图书,内容涵盖广泛,适用于对数据结构与算法有一定了解基础的读者。 - 书中包括了数据结构和算法的详细解释,以及相关的...
在"Algorithm-Data-Structure-And-Algorithm.zip"这个压缩包中,我们很可能找到了一系列关于算法和数据结构的深入研究材料,这对于提升编程技能和优化代码效率至关重要。 数据结构,是组织和存储数据的方式,它是...
"Algorithm-Data-Structure-master"很可能是一个包含实际代码实现的项目,这样的实践项目可以帮助学习者深入理解各种数据结构和算法的工作原理,并锻炼实际编程能力。 总结来说,算法和数据结构是构建高效计算机...
数据结构与算法,C描述。第二版,英文讲义PPT。 包含9章:Ch04-LISTS-STACKS-QUEUES(数据结构),Chapter3-Stacks-and-Queues,Chapter5 Binary Trees, chapter6 General trees,chapter7 Sorting,chapter8 Primary...
总之,《Algorithm-Data_Structure_and_Algorithms_Library》包含了一系列C语言实现的经典数据结构和算法,是学习和实践计算机科学基础的重要资源。通过深入理解和掌握这些内容,开发者能够编写出更加高效、优雅的...
Algorithm & Data Structure.md
The fourth edition of Data Structures and Algorithm Analysis in C++ describes data structures, methods of organizing large amounts of data, and algorithm analysis, the estimation of the running time ...
Data Structure Problems using C++.zip" 提供的信息表明,这是一个包含180多个算法和数据结构问题的资源包,使用C++编程语言进行实现。这个压缩包可能是为了帮助学习者熟悉和练习基础到高级的算法与数据结构,从而...
Algorithm-data-structure-and-algorithm-in-Swift.zip,swift语言的数据结构与算法实现,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
"Algorithm-data-structure-php-clanguage.zip"这个压缩包文件显然包含了关于算法和数据结构的学习资源,特别强调了PHP和C语言的实现方式。下面我们将深入探讨这两个关键概念及其在PHP和C语言中的应用。 首先,算法...
1. 数据结构的基础:在“FUNDAMENTAL DATA STRUCTURES”部分,书籍可能涵盖了以下数据结构的基础知识和实现细节。 - 数据类型的定义和概念,包括数据类型的分类和数据抽象。 - 原始数据类型,标准原始类型,子范围...