
C++
文章平均质量分 72
gxulg
这个作者很懒,什么都没留下…
展开
-
一个通用链表类
链表是必不可少的数据结构,很多运行时库都提供了现成的链表类。当然我们也可以自己实现它。下面就是一个例子。类的定义如下://****************************************************************************//// CLASS COBLIST DEFINATION////******************************原创 2005-02-17 11:21:00 · 2242 阅读 · 1 评论 -
与二叉树有关的一些操作:先序,中序,后序,层次遍历,计算深度,叶结点数
//先序遍历template void preorderOutput(tnode *t, const string& separator = " "){ // the recursive scan terminates on a empty subtree if (t != NULL) { cout nodeValue inorderOutput(t->lef原创 2005-06-23 11:08:00 · 2716 阅读 · 0 评论 -
选择排序
描述:从向量头部开始,找出第一小的放到前面,第二小的放到第二个位置。。。。。。template void selectionSort(vector& v){ // index of smallest item in each pass int smallIndex; // save the vector size in n int pass, j, n = v.size(); T temp;原创 2005-06-28 10:47:00 · 1189 阅读 · 0 评论 -
插入排序
描述:遍历向量,为每个元素找到它应该在的位置,插入。template void insertionSort(vector& v){ int i, j, n = v.size(); T target; // place v[i] into the sublist // v[0] ... v[i-1], 1 // so it is in the correct position fo原创 2005-06-28 10:51:00 · 1218 阅读 · 0 评论 -
基数排序
描述:将数依次按个位,十位,百位。。。排序// support function for radixSort()// distribute vector elements into one of 10 queues// using the digit corresponding to power// power = 1 ==> 1s digit// power = 10 ==>原创 2005-06-28 11:00:00 · 1282 阅读 · 0 评论 -
二叉树结点定义
#ifndef TREENODE#define TREENODE// 表示二叉树的一个结点template class tnode{ public: // tnode is a class implementation structure. making the // data public simplifies building class functions T nodeValue;原创 2005-06-23 10:56:00 · 2757 阅读 · 0 评论 -
二分搜索
template int binSearch(const T arr[], int first, int last, const T& target){ int mid; // index of the midpoint T midValue; // object that is assigned arr[mid] int origL原创 2005-06-28 10:40:00 · 1328 阅读 · 0 评论