- 博客(13)
- 资源 (16)
- 收藏
- 关注
原创 单向链表逆转(递归)
struct Node { int value; Node *next; }; //head为原始链表的头节点,p初始值为head,newHead用来存储逆转后的头节点 void reverse(Node *head,Node *p, Node* &newHead) { if (NULL == head) { newHead = NULL;
2012-11-22 22:46:08 671
原创 单向链表逆转(非递归)
#include using namespace std; struct Node { int value; Node *next; }; Node* reverse(Node *head) { Node *p = head; Node *q = NULL; while (NULL != p) { Node *temp = p-
2012-11-21 22:57:18 398
原创 二叉树后序遍历(非递归)
#include #include using namespace std; struct Node { int value; Node *left; Node *right; }; void postorderTraverse(Node *root) { if (NULL == root) { return; }
2012-11-20 20:51:12 362
原创 二叉树后序遍历(递归)
#include using namespace std; struct Node { int value; Node *left; Node *right; }; void postorderTraverse(Node *root) { if (NULL == root) { return; } postorder
2012-11-20 00:55:29 458
原创 二叉树中序遍历(非递归)
#include #include using namespace std; struct Node { int value; Node *left; Node *right; }; void inorderTraverse(Node *root) { if (NULL == root) { return; }
2012-11-20 00:29:55 551
原创 二叉树中序遍历(递归)
#include using namespace std; struct Node { int value; Node *left; Node *right; }; void inorderTraverse(Node *root) { if (NULL == root) { return; } inorder
2012-11-19 22:27:06 592
原创 二叉树先序遍历(非递归)
#include #include using namespace std; struct Node { int value; Node *left; Node *right; }; void preOrderTraverse(Node *root) { if (NULL == root) { return; } stack buf; buf.push(root);
2012-11-15 14:18:35 384
原创 二叉树先序遍历(递归)
#include using namespace std; struct Node { int value; Node *left; Node *right; }; void preorderTraverse(Node *root) { if (NULL == root) { return; } cout v
2012-11-15 00:35:18 413
原创 堆排序
void maxHeapify(int a[], int n, int k) { if (NULL == a) { return; } int left = 2*k + 1; int right = 2*k + 2; int max = k; if (left < n && a[max] < a[left]) { max = left; } if (right < n
2012-11-14 17:56:13 289
原创 单向链表应用
给出一个四则运算表达式,其中每个数字均为小于等于9且大于等于0。不考虑溢出,计算结果。表达式如"1+2*3-6+5-8/2+1+7"。 #include using namespace std; struct Node { int value; Node *next; }; int calculate(char a[]) { if (NULL == a)
2012-11-12 22:46:43 368
原创 全排列打印(二)
给出数字1,2,3。打印出序列:1, 2, 3, 12, 23, 13, 123。 #include using namespace std; bool status[3] = {false, false, false}; void print(int a[], int pos, int n) { if (pos == n) { for (int i
2012-11-09 00:00:53 392
原创 全排列打印(一)
给出数字1,2,3.打印出所有可能的排列。如:123, 132, 213, 231... #include using namespace std; void print(int a[], int begin, int n) { if (begin == n) { for (int i = 0; i < n; i++) {
2012-11-08 22:46:18 385
原创 单向链表归并排序
#include using namespace std; struct Node { int value; Node *next; }; Node* merge(Node *left, int leftLen, Node *right, int rightLen) { if (NULL == left || NULL == right) {
2012-11-08 03:05:31 420
exceptional c++ style中文版 pdf 刘未鹏译
2010-09-26
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人