卫士通A卷笔试题2.docx

上传人:b****6 文档编号:7313419 上传时间:2023-01-22 格式:DOCX 页数:11 大小:15.28KB
下载 相关 举报
卫士通A卷笔试题2.docx_第1页
第1页 / 共11页
卫士通A卷笔试题2.docx_第2页
第2页 / 共11页
卫士通A卷笔试题2.docx_第3页
第3页 / 共11页
卫士通A卷笔试题2.docx_第4页
第4页 / 共11页
卫士通A卷笔试题2.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

卫士通A卷笔试题2.docx

《卫士通A卷笔试题2.docx》由会员分享,可在线阅读,更多相关《卫士通A卷笔试题2.docx(11页珍藏版)》请在冰豆网上搜索。

卫士通A卷笔试题2.docx

卫士通A卷笔试题2

2014卫士通A卷笔试题

(2)

 

2.单链表反置。

 

1.structListNode

 

2.{

 

3.intm_nKey;

 

4.ListNode*m_pNext;

 

5.};

 

6.

 

7.#includestdafx.h

 

8.#include

 

9.#include

 

10.

 

11.usingnamespacestd;

 

12.

 

13.structListNode

 

14.{

 

15.intm_nKey;

 

16.ListNode*m_pNext;

 

17.};

 

18.

 

19.//构造链表

 

20.voidCreateList(ListNode*pHead)

 

21.{

 

22.fstreamfin(list.txt

 

23.ListNode*pNode=NULL;

 

24.ListNode*pTmp=NULL;

 

25.intdata;

 

26.findata;

 

27.while(data)

 

28.{

 

29.pNode=newListNode;

 

30.pNode-m_nKey=data;

 

31.pNode-m_pNext=NULL;

 

32.if(NULL==pHead)

 

33.{

 

34.pHead=pNode;

 

35.pTmp=pNode;

 

36.}

 

37.else

 

38.{

 

39.pTmp-m_pNext=pNode;

 

40.pTmp=pNode;

 

41.}

 

42.

 

43.findata;

 

44.}

 

45.}

 

46.

 

47.//翻转单链表

 

48.voidReverseLink(ListNode*pHead)

 

49.{

 

50.if(NULL==pHead)

 

51.{

 

52.return;

 

53.}

 

54.ListNode*pNode=pHead;

 

55.ListNode*Prev=NULL;

 

56.ListNode*pNext=NULL;

 

57.while(NULL!

=pNode)

 

58.{

 

59.pNext=pNode-m_pNext;

 

60.if(NULL==pNext)

 

61.{

 

62.pHead=pNode;

 

63.}

 

64.pNode-m_pNext=Prev;

 

65.Prev=pNode;

 

66.pNode=pNext;

 

67.}

 

68.}

 

69.

 

70.voidPrintList(ListNode*pHead)

 

71.{

 

72.if(NULL==pHead)

 

73.{

 

74.return;

 

75.}

 

76.ListNode*pNode=pHead;

 

77.while(NULL!

=pNode)

 

78.{

 

79.coutpNode-m_nKey  

 

80.pNode=pNode-m_pNext;

 

81.}

 

82.coutendl;

 

83.}

 

84.

 

85.int_tmain(intargc,_TCHAR*argv[])

 

86.{

 

87.ListNode*pHead=NULL;

 

88.cout原来的链表:

 

89.CreateList(pHead);

 

90.PrintList(pHead);

 

91.ReverseLink(pHead);

 

92.cout翻转的链表:

 

93.PrintList(pHead);

 

94.

 

95.return0;

 

96.}

 

3.实现atoi函数

 

1.#includestdio.h

 

2.#includectype.h

 

3.#includestdlib.h

 

4.

 

5./*

 

6.Convertsacharacterstringintoanintorlong

 

7.将一个字符串转化为整数

 

8.*/

 

9.intmy_atoi(chars[])

 

10.{

 

11.inti,n,sign;

 

12.

 

13.for(i=0;isspace(s[i]);i++);//跳过空白

 

14.

 

15.sign=(s[i]==-)?

-1:

1;

 

16.if(s[i]==+||s[i]==-)//跳过符号位

 

17.i++;

 

18.for(n=0;isdigit(s[i]);i++)

 

19.n=10*n+(s[i]-0//将数字字符转换成整形数字

 

20.returnsign*n;

 

21.}

 

22.

 

23./*

 

24.Convertsanintorlongintoacharacterstring

 

25.将一个整数转化为字符串

 

26.*/

 

27.voidmy_itoa(intn,chars[])

 

28.{

 

29.inti,j,sign;

 

30.

 

31.if((sign=n)0)//记录符号

 

32.n=-n;//使n成为正数

 

33.i=0;

 

34.do{

 

35.s[i++]=n%10+0//取下一个数字

 

36.}while((n/=10)//循环相除

 

37.

 

38.if(sign0)

 

39.s[i++]=-

 

40.s[i]=\0

 

41.for(j=i-1;jj--)//生成的数字是逆序的,所以要逆序输出

 

42.printf(%c,s[j]);

 

43.}

 

44.

 

45.

 

46.voidmain()

 

47.{

 

48.intn;

 

49.charstr[100];

 

50.my_itoa(-123,str);

 

51.printf(\n

 

52.printf(%d\n,my_atoi(123));

 

53.system(pause

 

54.}

 

四、问答

 

1.你对卫士通的了解?

 

2.说出你胜任这份工作的理由?

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1