随笔分类 - 典型笔试题
收集各个笔试题
摘要:void reverse(char* str){ char *end = str, *begin=str; char temp; while(*end!='\0') { end++; } end--; while(begin<=end) ...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 /* 4 题目:合并两个排序的链表 5 输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然是按照递增排序的。 6 链表结点定义如下: 7 struct ListNode 8 { 9 int m_nValue;10 ListNode *m_pNext;11 }12 */13 using namespace std;14 struct ListNode15 {16 int m_nValue;17 List...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 /* 4 题目:反转链表 5 定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。链表结点定义如下: 6 struct ListNode 7 { 8 int m_nKey; 9 ListNode* m_pNext;10 };11 */12 using namespace std;13 struct ListNode14 {15 int m_nKey;16 ListNode* m_pNext;17 };18 ListNode* ReverseList(ListNode* ...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 /* 4 题目:链表中倒数第k个节点 5 输入一个链表,输出该链表中倒数第k个结点.为了符合大多数人的习惯.本题从1开始计数,即链表的尾结点是倒数第一个结点。 6 比如一个链表有6个结点,从头结点开始它们的值依次是1,2,3,4,5,6这个链表的倒数第三个结点是值为4的结点. 7 struct ListNode 8 { 9 int m_nValue;10 ListNode* m_pNext;11 };12 */13 using namespace s...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 /* 4 题目:调整数组顺序使奇数位于偶数前面 5 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分. 6 */ 7 using namespace std; 8 9 void ReorderOddEvent(int *pData,unsigned int length)10 {11 int left = 0,right = length-1;12 while(left<right)13 {14 while...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 /* 4 题目:在O(1)时间删除链表结点 5 给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点。链表结点与函数定义如下: 6 struct ListNode 7 { 8 int m_nValue; 9 ListNode *m_pNext;10 };11 void DeleteNode(ListNode** pListHead,ListNode* pToBeDeleted);12 */13 using namespace st...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 #include 6 /* 7 题目:打印1到最大的n位数 8 输入数字n,按顺序打印出从1到最大的n位数的十进制数.比如输入3,则打印出1,2,3一直到最大的3位数即999 9 */10 using namespace std;11 12 bool Increment(char * number)13 {14 bool isOverflow = false;15 int nTakeOver = 0;16 int nLength = st...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 /* 6 题目:实现函数 doublePower(double base,int exponenet), 7 求base的exponenet次方,不得使用库函数,同时不需要考虑大数问题 8 */ 9 using namespace std;10 bool g_InvalidInput = false;11 bool equal(double num1,double num2)12 {13 if((num1 - num2 >-0.0000001)&&
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 /* 8 裴波那契数列 9 写一个函数:输入n,求裴波那契(Fibonacci)数列的第n项.10 裴波那契数列的定义如下:11 0 n=012 f(n) = 1 n=113 f(n-1)+f(n-2) n>1;14 15 题目二:一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法.16 */17 int Fibonaccire(unsi...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 /* 8 旋转数组的最小数字 9 题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转,输入10 一个递增排序的数组的一个旋转。输出旋转数组的最小元素。例如数组{3,4,5,1,2}11 为{1,2,3,4,5}的一个旋转,该数组的最小值为1.12 思路:遍历一遍找最小值.时间复杂度显然是O(n),这个思路显然达不到要求.13 */14 15 int Min(int *arr,int beg,i
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void Swap(int *lhs,int *rhs) 8 { 9 int temp = *lhs;10 *lhs = *rhs;11 *rhs = temp;12 }13 14 int Partition(int* Array,int begin,int end)15 {16 int ran = begin+ rand() % (end-begin+1);//生成一个从begin到end...
阅读全文
摘要:#include "stdafx.h"#include #include #include using namespace std;/* 重建二叉树题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树. 假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如 输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6}, 则重建出图所示的二叉树并输出它的头结点。二叉树结点的定义如下:*/struct BinaryTreeNode{ int m_nValue; BinaryTreeNode* m_p...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 /*从尾到头打印链表*/ 8 /* 9 题目:输入一个链表的头结点,从尾到头反过来打印出每个结点的值。10 */11 struct ListNode12 {13 int m_nValue;14 ListNode* m_pNext;15 };16 17 //根据后进先出的思想,考虑用栈的方法18 void PrintListReversingly_Iteratively(ListNode* pHead)19 ...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 struct ListNode 7 { 8 int m_nValue; 9 ListNode* m_pnext;10 };11 12 void InsertNodeTail(ListNode** L,int num)13 {14 ListNode* node = new ListNode();15 node->m_nValue = num;16 node->m_pnext = NULL;17 if(...
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 /*替换空格*/ 7 /* 8 题目:请实现一个函数,把字符串中的每个空格替换成"%20".例如输入"We are happy",则输出"We%20are%20happy". 9 */10 int ReplaceBlank(char string[],int length)11 {12 int i = 0;13 int blankNum=0;14 int strLength=
阅读全文
摘要:1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 /*二维数组中的查找*/ 7 /* 8 题目: 9 在一个二维数组中,每一行都按照从左到右递增的顺序排序,10 每一列都按照从上到下递增的顺序排序.请完成一个函数,11 输入这样的一个二维数组和一个整数,12 判断数组中是否含有该整数.13 */14 bool FindNumber(int *matrix,int columns,int rows,int key)15 {16 bool found = false;17 if(ma..
阅读全文

浙公网安备 33010602011771号