08 2011 档案

摘要:求整型数组中最大子串方法总结:View Code 1 #include <iostream> 2 #include <cassert> 3 4 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 5 //判断两已排序数组是否有相同元素 6 bool sameNumber(const int* preArray, int preSize, const int* postArray, int postSize) 7 { 8 assert( preArray && postArray); 9 int preIndex = 阅读全文
posted @ 2011-08-30 16:12 lifengzhong 阅读(241) 评论(0) 推荐(0)
摘要:题目一: 线性时间内判断两有序数组是否有相同元素.题目二: 求数组最大子串(元素全负时返回0)View Code 1 #include <iostream> 2 #include <cassert> 3 //判断两已排序数组是否有相同元素 4 bool sameNumber(const int* preArray, int preSize, const int* postArray, int postSize) 5 { 6 assert( preArray && postArray); 7 int preIndex = 0; 8 int postInde 阅读全文
posted @ 2011-08-29 16:56 lifengzhong 阅读(274) 评论(0) 推荐(0)
摘要:题目: 链表环判断,不同链表是否有交点判断View Code 1 #include <iostream> 2 #include <cassert> 3 4 typedef struct __node { 5 int value; 6 __node* next; 7 } NODE, *PNODE; 8 9 bool circleJudge(const PNODE head)10 {11 assert(head);12 PNODE oneOffset = head, twoOffset = head->next;13 while (tru... 阅读全文
posted @ 2011-08-29 00:06 lifengzhong 阅读(232) 评论(0) 推荐(0)
摘要:题目:常用库函数实现。 1 #include <iostream> 2 #include <cassert> 3 void* myMemCpy(void* dest, const void* src, size_t length) 4 { 5 assert(dest && src); 6 char* charDest = static_cast<char*>(dest); 7 const char* charSrc = static_cast<const char*>(src); 8 bool special = charSrc 阅读全文
posted @ 2011-08-26 11:47 lifengzhong 阅读(210) 评论(0) 推荐(0)
摘要:题目:将单链表逆置#include <iostream>typedef struct __node{ int value; __node* next;} NODE, *PNODE;PNODE reverse(PNODE head){ if (!head) { return head; } PNODE curNode = head; PNODE nextNode = head->next; head->next = NULL; while (nextNode) { PNODE afterNextNode = nextNode->next; nextNode-> 阅读全文
posted @ 2011-08-25 14:53 lifengzhong 阅读(503) 评论(0) 推荐(1)
摘要:题目:不使用中间变量,逆置字符串。#include <iostream>#include <cstring>void reverse_without_temp(char* array){ char* first = array; char* last = array + strlen(array) - 1; while (first < last) { *first ^= *last; *last ^= *first; *first ^= *last; ++first; --last; }}void reverse_without_temp(char* array 阅读全文
posted @ 2011-08-24 15:54 lifengzhong 阅读(233) 评论(0) 推荐(0)
摘要:题目描述: 给定位数n(n >= 0 && n <= 10),生成n位随机数,随机数内无重复数字.隐含条件:最高位不能为0 1 #include <iostream> 2 #include <time.h> 3 #include <set> 4 #include <vector> 5 6 bool randNumber(int n, unsigned long& result) 7 { 8 if (n <= 0 || n > 10) { 9 return false;10 }11 std::vect 阅读全文
posted @ 2011-08-24 15:37 lifengzhong 阅读(224) 评论(0) 推荐(0)