上一页 1 ··· 4 5 6 7 8 9 10 11 12 下一页
摘要: 题目:删除字符串中的数字并压缩字符串。举例:输入字符串"abc123de4fg56", 输出"abcdefg"。要求:不开辟新空间,时间复杂度为O(n)。答:#include "stdafx.h"#include <iostream>using namespace std;//删除字符串中的数字并压缩字符串void RemoveNumberChar(char *str){ if (NULL == str) { return; } char *p = str; char *pNewStr = str; while (*p ! 阅读全文
posted @ 2012-08-28 20:08 venow 阅读(3107) 评论(0) 推荐(1) 编辑
摘要: 题目:给定链表的头指针和一个结点指针,在O(1)时间内删除该结点,链表结点的定义如下:struct ListNode{ int m_nKey; ListNode* m_pNext;};函数的声明如下:void DeleteNode(ListNode *pListHead, ListNode *pToBeDeleted);答:#include "stdafx.h"#include <iostream>#include <fstream>#include <ctime>using namespace std;struct ListNode{ 阅读全文
posted @ 2012-08-28 20:00 venow 阅读(896) 评论(0) 推荐(0) 编辑
摘要: 题目:输入两个字符串,从第一个字符串中删除第二个字符串中所有的字符。举例:输入"They are students."和"aeiou",则输出之后的第一个字符串变成"Thy r stdnts."。答:#include "stdafx.h"#include <iostream>using namespace std;//在字符串中删除特定的字符void DeleteSpecialChar(char *pStr, const char *pDelStr){ const int length = 256; i 阅读全文
posted @ 2012-08-28 19:51 venow 阅读(470) 评论(0) 推荐(0) 编辑
摘要: 题目:数组中有一个数组出现的次数超过了数组长度的一半,找出这个数字。答:#include "stdafx.h"#include <iostream>using namespace std;//查找数组中超过出现次数超过一半的数字int FindNumber(int arr[], int length){ if (NULL == arr || length <= 0) { return -1; } int nValue = arr[0]; int count = 1; for (int i = 1; i < length; i++) { ... 阅读全文
posted @ 2012-08-27 22:00 venow 阅读(379) 评论(0) 推荐(0) 编辑
摘要: 题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个排好序的数组的一个旋转。输出旋转数组的最小值。举例:输入数组{3, 4, 5, 1, 2}为{1, 2, 3, 4, 5}的一个旋转,该数组的最小值为1。答:#include "stdafx.h"#include <iostream>using namespace std;//查找旋转数组中的最小元素int FindMinValue(int arr[], int length){ int low = 0; int high = length - 1; while (low < 阅读全文
posted @ 2012-08-27 21:49 venow 阅读(460) 评论(1) 推荐(0) 编辑
摘要: 题目:输入一个正数n,输出所有和为n的连续正数序列举例:输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以输出3个连续序列1,2,3,4,5;4,5,6;7,8。答:#include "stdafx.h"#include <iostream>using namespace std;//求和为n的连续正数序列void FindSequenceNumber(int n){ if (n <= 0) { return; } int first = 1; int last = 2; int end = (n + 1) / 2; int... 阅读全文
posted @ 2012-08-27 19:22 venow 阅读(328) 评论(0) 推荐(0) 编辑
摘要: 题目:输入一个整数数组,调整数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分。要求:时间复杂度为O(n)答:#include "stdafx.h"#include <iostream>using namespace std;bool IsOddNumber(int n){ return (n & 1) != 0;}void AdjustArray(int arr[], int length, bool (*Func)(int)){ int begin = 0; int end = length - 1; while (begi 阅读全文
posted @ 2012-08-27 19:19 venow 阅读(288) 评论(0) 推荐(0) 编辑
摘要: 题目:两个单链表,找出它们的第一个公共结点。链表的结点定义为:struct ListNode{ int m_nKey; ListNode* m_pNext;};答:#include "stdafx.h"#include <iostream>#include <fstream>using namespace std;struct ListNode{ int m_nKey; ListNode* m_pNext;};//构造链表void CreateList(ListNode *&pHead, fstream &fin, ListNode 阅读全文
posted @ 2012-08-27 19:15 venow 阅读(529) 评论(0) 推荐(0) 编辑
摘要: 题目:输入一个链表头结点,从尾到头反过来输出每个结点的值。链表结点定义如下:struct ListNode{ int m_nKey; ListNode* m_pNext;};答:1、可以先把链表逆置,然后再输出,具体参考 http://www.cnblogs.com/venow/archive/2012/08/26/2657559.html 这里我们使用另一种更为简单的方法:递归#include "stdafx.h"#include <iostream>#include <fstream>using namespace std;struct List 阅读全文
posted @ 2012-08-26 20:46 venow 阅读(705) 评论(0) 推荐(0) 编辑
摘要: 题目:输入一个单向链表,将该单链表逆置。举例:原来链表为1->2->3->4->5翻转为5->4->3->2->1链表结点定义如下:struct ListNode{ int m_nKey; ListNode* m_pNext;};答:#include "stdafx.h"#include <iostream>#include <fstream>using namespace std;struct ListNode{ int m_nKey; ListNode* m_pNext;};//构造链表void C 阅读全文
posted @ 2012-08-26 18:12 venow 阅读(21854) 评论(6) 推荐(1) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 下一页