2011年5月9日

单链表反转

摘要: void reverse(List* list){ Node* before = list->first; if (before != NULL) { Node* after = before->next; before->next = NULL; while (after) { //交换指针 Node* temp = after->next; after->next = before; before = after; after = temp; } }} 阅读全文

posted @ 2011-05-09 21:43 NULL00 阅读(454) 评论(0) 推荐(0) 编辑

非递归实现fibonacci数列

摘要: 下面用两个方法实现fibonacci数列,一个是递归的,一个是非递归的,由于递归需要不断的开辟新的栈,并释放开辟的栈,因而更耗时,但是在理解上却容易些。#include <iostream>#include <time.h>using namespace std;int recursive_method(int n);int non_recursive_method(int n);int main(){ clock_t t3 = clock(); printf("%d\n", non_recursive_method(40)); clock_t t4 阅读全文

posted @ 2011-05-09 21:34 NULL00 阅读(2762) 评论(0) 推荐(0) 编辑

导航