第一范文网 - 专业文章范例文档资料分享平台

C# ASP NET面试题附答案

来源:用户分享 时间:2025/6/9 0:48:26 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

18. lpIter->Next = NULL; 19. LPLINKLIST lpPrev = NULL; 20. 21. bool bInserted = false; 22. for ( LPLINKLIST lpI = lpHead; 23. lpI != NULL; 24. lpPrev = lpI, lpI = lpI->Next ) 25. { 26. if ( lpIter->Value < lpI->Value ) 27. { 28. lpIter->Next = lpI; 29. if ( lpPrev == NULL ) 30. lpHead = lpIter; 31. else 32. lpPrev->Next = lpIter; 33. 34. bInserted = true; 35. break; 36. } 37. } 38. 39. if ( !bInserted ) 40. lpPrev->Next = lpIter; 41. 42. lpIter = lpNext; 43. } 44.

45. return lpHead; 46. }

Write a function to print the Fibonacci numbers.

int fib ( int n ) { if (n == 0) return 1; else return fib(n-1) + fib(n-2); }

int fibo (int n) { int i, current, one_back, two_back; if (n <= 1) return 1; else { one_back = 1; two_back = 1; for ( i = 2; i <= n; i++) { current = one_back + two_back; one_back = two_back; two_back = current; } /* end for loop */ } /* end else block */ return current; }

有一个有序数组,其中可能包含重复的元素,去除其重复的部分返回数组的长度。如一个数组包含:1,3,7,7,8,9,9,9,10,运行后应当为1,3,7,8,9,10,返回长度6。

private static int CountAfterRemoveDups(int[] data) {

if ( data == null ) throw new ArgumentNullException(\ if ( data.Length == 0 ) return 0;

int result = 1;

int lastNondup = data[0];

for ( int i = 1; i < data.Length; ++i ) {

if ( data[i] != lastNondup ) {

result++;

lastNondup = data[i]; } }

return result; }

将一个字符串中的整数输出(比如“14ab5eer87”,应该输出“14,5,87”)。易犯的错误:没有分组输出,即输出为14587了。

private static string PrintGroup(string data) {

if ( data == null ) throw new ArgumentNullException(\ char[] result = new char[data.Length];

int resultIter = 0; bool doGroup = false;

foreach ( char c in data ) {

if ( c >= '0' && c <= '9' ) {

result[resultIter++] = c; doGroup = true; } else {

if ( doGroup ) {

result[resultIter++] = ','; doGroup = false; } } }

return new string(result); }

Implement an algorithm to sort an array. Why did you pick the method you did?

Bubble sort:

for(int x=0; x

Quick Sort:

void swap(int *x,int *y) { int temp; temp = *x; *x = *y; *y = temp; }

int choose_pivot(int i,int j ) { return((i+j) /2); }

void quicksort(int list[],int m,int n) { int key,i,j,k; if( m < n) { k = choose_pivot(m,n); swap(&list[m],&list[k]); key = list[m]; i = m+1; j = n; while(i <= j) { while((i <= n) && (list[i] <= key)) i++; while((j >= m) && (list[j] > key)) j--; if( i < j) swap(&list[i],&list[j]); } // swap two elements swap(&list[m],&list[j]);

}

}

// recursively sort the lesser list quicksort(list,m,j-1); quicksort(list,j+1,n);

Insertion Sort:

void insertion_sort(int x[],int length) {

int key,i;

for(int j=1;j

key=x[j]; i=j-1;

while(x[i]>key && i>=0) {

x[i+1]=x[i]; i--; }

x[i+1]=key; } }

Switch every pair of words in a string (\

private static string ReverseWordPair(string input) {

if (string.IsNullOrEmpty(input))

throw new ArgumentNullException(\);

char[] result = new char[input.Length]; int resultIter = 0; int begin = 0;

// skip leading whitespace

while (begin < input.Length && input[begin] == ' ') {

result[resultIter++] = input[begin]; begin++; }

ReverseWordPairImp(result, resultIter, input, begin);

return new string(result); }

private static void ReverseWordPairImp(char[] result, int resultIter, string input, int inputIter) {

int[] indics = new int[2]; int i = inputIter;

indics[0] = inputIter;

for (; i < input.Length; ++i) {

搜索更多关于: C# ASP NET面试题附答案 的文档
C# ASP NET面试题附答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c69bau6hyxa9ersb9r12w_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top