随笔分类 -  数据结构与算法

转:把二元查找树转变成排序的双向链表
摘要:// 1:构造二叉查找树;// 2:中序遍历二叉查找树,因此结点按从小到大顺序访问,假设之前访问过的结点已经调整为一个双向链表,那么// 只需要将当前结点连接至双向链表的最后一个结点即可,访问完后,双向链表也就调整完了#include <iostream>using namespace std;struct BSTreeNode{ int m_nValue; // value of node BSTreeNode *m_pLeft; // left child of node BSTreeNode *m_pRight; // right child of node};void... 阅读全文

posted @ 2013-05-10 09:22 liyanfasd 阅读(159) 评论(0) 推荐(0)

C语言获取集合幂集
摘要:思路:假设有集合中有3个元素,则该集合的幂集有23=8个子集元素 : 1 2 3二进制:0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1若二进制数组中对应的是1 ,则输出该元素;若二进制数组中对应的是0 ,则不输出。程序如下: 1 #include "stdio.h" 2 3 void main() 4 { 5 int i,j,k; 6 int a[3]={1,2,3}; 7 int b[3]={0,0,0}; 8 for(j=0;j<8;j++) 9 {10 ... 阅读全文

posted @ 2012-05-20 22:15 liyanfasd 阅读(966) 评论(0) 推荐(0)

快速排序算法-C语言
摘要:快速排序是在实践中最快的已知排序算法,它的平均时间是O(NlogN),最坏情形为O(N2),但快速排序是一种不稳定的排序算法。C语言程序如下:typedef int ElementType; //对类型变量起别名,提高程序可移植性、可读性 void QuickSort(ElementType A[],int left,int right) { int i,j; ElementType pivot; i=left; j=right; pivot=A[left]; if(left>=right) return ; whil... 阅读全文

posted @ 2012-04-24 12:07 liyanfasd 阅读(239) 评论(0) 推荐(0)

导航