當(dāng)前位置:高考知識(shí)網(wǎng) > 招聘筆試題 > 正文
三、編程題
1.比較字符串大小,如果字符串1大于字符串2,返回1,相等返回0,小于則返回-1;
1. int strcmp(const char* str1, const char* str2)
2. {
3. int ret = 0;
4. while(!(ret=*(unsigned char*)str1-*(unsigned char*)str2) && *str1)
5. {
6. str1++;
7. str2++
8. }
9.
10.
11. if (ret < 0)
12. {
13. return -1;
14. }
15. else if (ret > 0)
16. {
17. return 1;
18. }
19. return 0;
20. }
2.單鏈表反置。
1. struct ListNode
2. {
3. int m_nKey;
4. ListNode* m_pNext;
5. };
6.
7. #include "stdafx.h"
8. #include
9. #include
10.
11. using namespace std;
12.
13. struct ListNode
14. {
15. int m_nKey;
16. ListNode* m_pNext;
17. };
18.
19. //構(gòu)造鏈表
20. void CreateList(ListNode *&pHead)
21. {
22. fstream fin("list.txt");
23. ListNode *pNode = NULL;
24. ListNode *pTmp = NULL;
25. int data;
26. fin>>data;
27. while (data)
28. {
29. pNode = new ListNode;
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. fin>>data;
44. }
45. }
46.
47. //翻轉(zhuǎn)單鏈表
48. void ReverseLink(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. void PrintList(ListNode *pHead)
71. {
72. if (NULL == pHead)
73. {
74. return;
75. }
76. ListNode *pNode = pHead;
77. while (NULL != pNode)
78. {
79. cout<
m_nKey<<" ";
80. pNode = pNode->m_pNext;
81. }
82. cout<
83. }
84.
85. int _tmain(int argc, _TCHAR* argv[])
86. {
87. ListNode *pHead = NULL;
88. cout<<"原來(lái)的鏈表:";
89. CreateList(pHead);
90. PrintList(pHead);
91. ReverseLink(pHead);
92. cout<<"翻轉(zhuǎn)的鏈表:";
93. PrintList(pHead);
94.
95. return 0;
96. }
3.實(shí)現(xiàn)atoi函數(shù)
1. #include "stdio.h"
2. #include "ctype.h"
3. #include "stdlib.h"
4.
5. /*
6. Converts a character string into an int or long
7. 將一個(gè)字符串轉(zhuǎn)化為整數(shù)
8. */
9. int my_atoi(char s[])
10. {
11. int i,n,sign;
12.
13. for(i=0;isspace(s[i]);i++); //跳過(guò)空白
14.
15. sign=(s[i]=='-')?-1:1;
16. if(s[i]=='+'||s[i]==' -') //跳過(guò)符號(hào)位
17. i++;
18. for(n=0;isdigit(s[i]);i++)
19. n=10*n+(s[i]-'0'); //將數(shù)字字符轉(zhuǎn)換成整形數(shù)字
金山職業(yè)技術(shù)學(xué)院對(duì)比四川汽車職業(yè)技術(shù)學(xué)院哪個(gè)好 附分..
時(shí)間:2025-05-22 09:08:12成都銀杏酒店管理學(xué)院在重慶高考招生計(jì)劃人數(shù)和專業(yè)代..
時(shí)間:2025-05-22 09:05:01四川上山東理工大學(xué)多少分 分?jǐn)?shù)線及排名
時(shí)間:2025-05-22 09:01:18江西高考理科533分排名多少 排名多少位次
時(shí)間:2025-05-22 08:57:21大連東軟信息學(xué)院對(duì)比甘肅民族師范學(xué)院哪個(gè)好 附分?jǐn)?shù)線..
時(shí)間:2025-05-22 08:53:39廣東高考455至460分左右物理可以上什么大學(xué)
時(shí)間:2025-05-22 08:49:52
中國(guó)點(diǎn)擊率最高的一篇文章 !2023-08-13 03:45:29
海南上長(zhǎng)春工業(yè)大學(xué)多少分 分?jǐn)?shù)線及排名2025-05-22 09:28:45
科爾沁藝術(shù)職業(yè)學(xué)院對(duì)比山東水利職業(yè)學(xué)院哪個(gè)好 附分?jǐn)?shù)線排名2025-05-22 09:25:00
呼和浩特職業(yè)學(xué)院對(duì)比山西警官職業(yè)學(xué)院哪個(gè)好 附分?jǐn)?shù)線排名2025-05-22 09:22:04
四川工程職業(yè)技術(shù)學(xué)院在上海高考招生計(jì)劃人數(shù)和專業(yè)代碼(參考)2025-05-22 09:19:52
泰山科技學(xué)院對(duì)比西安理工大學(xué)高科學(xué)院哪個(gè)好 附分?jǐn)?shù)線排名2025-05-22 09:16:28
江西航空職業(yè)技術(shù)學(xué)院在云南高考招生計(jì)劃人數(shù)和專業(yè)代碼(參考)2025-05-22 09:13:20
遼寧特殊教育師范高等專科學(xué)校對(duì)比江西工商職業(yè)技術(shù)學(xué)院哪個(gè)好 附分?jǐn)?shù)線排名2025-05-22 09:10:51
網(wǎng)易汽車新聞編輯筆試題和面試題答案2023-08-12 00:11:14
網(wǎng)易筆試題和面試題答案2023-08-15 08:46:43
NHN CHINA公司筆試題和面試題答案2023-08-12 04:04:06 




