数据结构
云斜月
这个作者很懒,什么都没留下…
展开
-
单链表广义表的几种节点表示方法
//复合类表示法class List;class LinkNode{friend class List;private:int data;LinkNode *next;};class List{public://一些公共操作 private:LinkNode *first;}; //内嵌类表示法: class List { public: private: class LinkNode原创 2013-04-25 14:53:25 · 2656 阅读 · 0 评论 -
二叉树的非递归遍历思想
前序遍历算法思想: 判断该二叉树是否为空,若为空则退出遍历。压NULL入栈。访问根结点。右孩子如果非空则进栈,否则不做任何事情。如果左孩子非空,则进入左孩子,转到步骤3,否则出栈,转到步骤3。 伪代码: stack S; //空栈S, if root==NULL return; else { TreeNode *p; p=roo原创 2013-05-10 13:27:59 · 1141 阅读 · 0 评论 -
二叉树的简单创建和输出
这个二叉树只是简单的写出了创建的思想及存储结构,没有考虑一些细节性的东西,#include using namespace std; class Tree; class TreeNode { friend class Tree; TreeNode():Lchild(NULL),Rchild(NULL){} TreeNode(int d,TreeNode *l = NULL,TreeNode *r原创 2013-05-09 10:29:04 · 917 阅读 · 0 评论 -
简单插入排序
#include using namespace std; void swap(int &a, int &b) { int temp = a; a = b; b = temp; } void insert_sort(int arr[], int len) //插入排序 { if (arr == NULL || len < 0) return; int i = 0, k = 0;原创 2014-07-21 17:00:09 · 741 阅读 · 0 评论 -
求序列中最长子序列的值
void scan(int arr[],int len) { int maxsofar = 0; int maxendinghere = 0; for (int i = 0; i < len; i++) { maxendinghere = max(maxendinghere + arr[i], 0); maxsofar = max(maxsofar,maxendinghere);原创 2014-07-24 11:06:38 · 662 阅读 · 0 评论