Welcom to RO_wsy's blog

随笔分类 -  数据结构

摘要:二叉排序树又称二叉查找树,是一种的高效的查找数据结构,查找效率等同二分法。 以下是二叉查找树的一种简单模板实现:#include <iostream>using namespace std;template <typename T>class BinSearchTree{public: typedef Node* tree; BinSearchTree():rp(NULL), n(){} ~BinSearchTree(){ _clear(); n = 0; } void insert(const T& d){ _insert(rp, new Node(d)); 阅读全文
posted @ 2012-06-24 15:39 RO_wsy 阅读(197) 评论(0) 推荐(0)
摘要:简单的单链表模板实现:#include<iostream>using namespace std;template <typename T>class List{public: //构造函数 List():head(NULL), len(0){} //析构函数 ~List(){ clear(); } //判断链表是否为空 bool empty()const{ return head == NULL; } //返回链表元素的个数 int size()const{ return len; } //遍历链表 void travel()const{ if(empty()) re 阅读全文
posted @ 2012-06-24 10:49 RO_wsy 阅读(290) 评论(0) 推荐(0)