1、Interview+Question+AnswersReverse a Singly Linked List without using Recursion. / / Revert a single linked list / / a single linked list / a single linked list public static SingleLinkedListNode Reverse(SingleLinkedListNode root) if (root = null) throw new ArgumentNullException(root); SingleLinkedLi
2、stNode iter = root, next = root.Next; SingleLinkedListNode newRoot = root; root.Next = null; while (next != null) newRoot = next.Next; next.Next = iter; iter = next; next = newRoot; return iter; Reverse a Singly Linked List with using Recursion.编程找出N以下的所有素数void findPrimes(bignum topCandidate) bignum
3、 candidate = 2; while(candidate = topCandidate) bignum trialDivisor = 2; int prime = 1; while(trialDivisor * trialDivisor 0) & char.IsWhiteSpace(inputlastIndex - 1) lastIndex-;9. 10. int appendIndex = 0;11. for (int i = lastIndex - 1; i = 0; i-)12. 13. char c = inputi;14. / if (char.IsWhiteSpace(inp
4、uti)15. if ( c = | c = t | c = n | c = r )16. 17. for (int j = i + 1; j lastIndex; +j)18. sbappendIndex+ = inputj;19. 20. sbappendIndex+ = inputi;21. lastIndex = i;22. 23. 24. 25. for (int j = 0; j lastIndex; +j)26. sbappendIndex+ = inputj;27. 28. return new string(sb);29. Write a function that take
5、s in a string parameter and checks to see whether or not it is an integer, and if it is then return the integer value.1. public static int Parse(string args)2. 3. / Author: Yimin Shi. 2008-05-304. / 这个函数也有一个BUG, 比如在处理字符串 -5147483648时候,就不会throw OverflowException.5. if (string.IsNullOrEmpty(args)6. th
6、row new ArgumentNullException(args);7. 8. int iter = 0;9. bool bNegative = false;10. int result = 0;11. / Skip whites 12. while (iter args.Length & (argsiter = ) iter+;13. 14. if (argsiter = -)15. 16. bNegative = true;17. iter+;18. 19. else if (argsiter = +)20. iter+;21. 22. for (; iter = 0 & argsit
7、er = 9)25. 26. int cur = argsiter - 0; 32. 33. checked(result *= 10);34. 35. result = bNegative ? result - cur36. : result + cur;42. 43. else44. break;45. 46. 47. / Skip whites 48. while (iter args.Length & (argsiter = ) iter+;49. if (iter != args.Length)50. throw new ArgumentException();51. 52. ret
8、urn result;53. Implement strstr() (or some other string library function).char * _cdecl strstr ( const char * str1, const char * str2 ) char *cp = (char *) str1; char *s1, *s2; if ( !*str2 ) return(char *)str1); while (*cp) s1 = cp; s2 = (char *) str2; while ( *s1 & *s2 & !(*s1-*s2) ) s1+, s2+; if (
9、!*s2) return(cp); cp+; return(NULL);Implement an algorithm to print out all files below a given root node.public abstract class AbstractGraph : AbstractContainer, Graph protected int numberOfVertices; protected int numberOfEdges; protected Vertex vertex; public void BreadthFirstTraversal( Visitor vi
10、sitor, int start) bool enqueued = new boolnumberOfVertices; for (int v = 0; v numberOfVertices; +v) enqueuedv = false; Queue queue = new QueueAsLinkedList(); queue.Enqueue(vertexstart); enqueuedstart = true; while (!queue.IsEmpty & !visitor.IsDone) Vertex v = (Vertex)queue.Dequeue(); visitor.Visit(v
11、); foreach (Vertex to in v.Successors) if (!enqueuedto.Number) queue.Enqueue(to); enqueuedto.Number = true; 现有一单链表,输出从尾端开始的第5个数值,并写出相应的测试用例Given two linked lists which have data in ascending order, how would you merge them/ / Merge two sorted linked list in sorted order / / the first sorted linked l
12、ist / the second sorted linked list / / The result sorted linked list / / For e.g. / SingleLinkedListNode.PrintLinkedList(SingleLinkedListNode.OrderedMerge(SingleLinkedListNode.InitializeTestList(new int 1, 2, 4, 5, 6, 7, 8, 9 ), SingleLinkedListNode.InitializeTestList(new int 3, 6, 8, 9, 10 ); / -
13、returns - / 1 - 2 - 3 - 4 - 5 - 6 - 6 - 7 - 8 - 8 - 9 - 9 - 10 - / / SingleLinkedListNode.PrintLinkedList(SingleLinkedListNode.OrderedMerge(SingleLinkedListNode.InitializeTestList(new int 1, 2, 4, 5, 7 ), SingleLinkedListNode.InitializeTestList(new int 3, 6, 8, 9, 10 ); / - returns - / 1 - 2 - 3 - 4
14、 - 5 - 6 - 7 - 8 - 9 - 10 - / public static SingleLinkedListNode OrderedMerge(SingleLinkedListNode first, SingleLinkedListNode second) if (first = null) throw new ArgumentNullException(first); if (second = null) throw new ArgumentNullException(second); SingleLinkedListNode less = first.Value second.
15、Value ? first : second; SingleLinkedListNode newRoot = less; SingleLinkedListNode iter = newRoot; less = less.Next; while (less != null & larger != null) if (less.Value larger.Value) iter.Next = less; less = less.Next; else iter.Next = larger; larger = larger.Next; iter = iter.Next; while (less != n
16、ull) iter = iter.Next = less; less = less.Next; while (larger != null) iter = iter.Next = larger; larger = larger.Next; return newRoot; Implement an algorithm to do wild card string matching.1. private static bool WildCardMatch(string pattern, string input)2. 3. if (string.IsNullOrEmpty(pattern)4. t
17、hrow new ArgumentNullException(pattern);5. if (string.IsNullOrEmpty(input)6. throw new ArgumentNullException(input);7. 8. int inputIter = 0;9. int patternIter = 0;10. for (; patternIter pattern.Length; +patternIter)11. 12. if (patternpatternIter = *)13. 14. while (patternIter pattern.Length - 1) & (
18、patternpatternIter + 1 = *) patternIter+;15. if (patternIter = pattern.Length - 1)16. return true;17. 18. while (patternIter pattern.Length) &19. (inputIter = input.Length) break;28. 29. if (patternpatternIter != inputinputIter+)30. return false;31. 32. 33. 34. return patternIter = pattern.Length &
19、inputIter = input.Length;35. Write a routine that prints out a 2-D array in spiral order! int left=0,top=0,right=3,bottom=3,CurrentRow=0,CurrentCulom=0,step; int, Num = new int, 1, 2, 3,4 , 5, 6 ,7,8, 9,10,11,12 , 13,14,15,16 ; /rule define:X,Y,if X=0,traversal colum,if X=1,traversal row;if Y=1,incr
20、ease by degrees,if Y=-1,decrease by degrees /int, rule = new int, 1, 1 , 0, 1 , 1, -1 , 0, -1 ;/clockwise int, rule = new int, 0, 1 , 1, 1 , 0, -1 , 1, -1 ; /counter-clockwise int a = Num.Rank; int b = Num.Length; int process=0; while (true) switch (ruleprocess, 0) case 1:/row step = ruleprocess, 1;
21、 for (; CurrentCulom = left & CurrentCulom = top & CurrentRow bottom | left right) break; process =( process + 1) % 4; Implement a string.Replace.1. public static string Replace(string strSrc, string oldStr, string newStr)2. /Implement a string.Replace.3. 4. if (string.IsNullOrEmpty(strSrc) | string.IsNullOrEmpty(oldStr) | newStr = null)5. throw
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1