摘要: 题目:将单链表逆置#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 阅读(494) 评论(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 阅读(222) 评论(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 阅读(205) 评论(0) 推荐(0) 编辑