随笔分类 - 数据结构
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 typedef int ElementType; 6 7 struct HeapStruct; 8 typedef struct HeapStruct *PriorityQueue; 9 10 PriorityQueue Initialize( int MaxElements); 11 12 void DestoryQueue(PriorityQueue H); 13 void MakeEmpty(PriorityQueu
阅读全文
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 6 typedef int ElementType; 7 typedef unsigned int Index; 8 9 struct ListNode; 10 typedef struct ListNode *Position; 11 struct HashTbl; 12 typedef struct HashTbl *HashTable; 13 14 15 Index Hash( const int Key, int
阅读全文
摘要:动态平衡技术Adelson-Velskii 和 Landis 提出了一个动态地保持二叉排序树平衡的方法,其基本思想是: 在构造二叉排序树的过程中,每当插入一个结点时,首先检查是否因插入而破坏了树的平衡性,如果是因插入结点而破坏了树的平衡性,则找出其中最小不平衡子树,在保持排序树特性的前提下,调整最小不平衡子树中各结点之间的连接关系,以达到新的平衡。通常将这样得到的平衡二叉排序树简称为AVL 树。那么什么是 最小不平衡子树 以离插入结点最近、且平衡因子绝对值大于 1 的结点作根结点的子树。为了简化讨论,不妨假设二叉排序树的最小不平衡子树的根结点为 A ,则调整该子树的规律可归纳为下列四种情况..
阅读全文
摘要:1 typedef struct QNode 2 { 3 QElemType data; 4 struct QNode *next; 5 6 }QNode,*QueuePtr; 7 8 9 typedef struct 10 { 11 QueuePtr front, rear; 12 }LinkQueue; 13 14 15 void 16 InitQueue(LinkQueue *Q) 17 { 18 Q->front = Q->next = malloc(sizeof( struct QNode...
阅读全文
摘要:#include <stdio.h>#include <stdlib.h>#include <string.h>#define ElementType intstruct Node;typedef struct Node *PtrToNode;typedef PtrToNode Stack;int IsEmpty( Stack S); Stack CreateStack(void);void DisPoseStack( Stack S); void MakeEmpty( Stack S); void Push(ElementType X, Stack S);
阅读全文
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 4 5 6 typedef int ElementType; 7 8 struct TreeNode; 9 typedef struct TreeNode *Position; 10 typedef struct TreeNode *SearchTree; 11 12 13 SearchTree MakeEmpty( SearchTree T ); 14 Position Find(ElementType X,SearchTree T); 15 Position Fin...
阅读全文
摘要:C语言,结构体(struct) 用法结构(struct) 结构是由基本数据类型构成的、并用一个标识符来命名的各种变量的组合。结构中可以使用不同的数据类型。 1. 结构说明和结构变量定义 在Turbo C中, 结构也是一种数据类型, 可以使用结构变量, 因此, 象其它类型的变量一样, 在使用结构变量时要先对其定义。 定义结构变量的一般格式为: struct 结构名 { 类型 变量名; 类型 变量名; ... } 结构变量; 结构名是结构的标识符不是变量名。 类型为第二节中所讲述的五种数据类型(整型、浮点型、字符型、指针型和无值型)。 构成结构的每一个类型变量称为结构成员, 它象数组的元素一样,
阅读全文
摘要:int Partition(int a[], int p, int r){ int left =p; int right = r; int provint = a[left]; while( left < right) { while( left < right && a[right] >= provint) right --; a[left] = a[right]; while(left < right && a[left] <= provint) left ++; a[right] = a[le...
阅读全文
摘要:归并排序的程序: voidmergeSort(int a[], int first, int last, int temp[]){ int mid ; if ( first < last) { mid = (first + last)/2; //分解 mergeSort(a,first,mid,temp); mergeSort(a,mid +1,last,temp); //合并 mergeArray(a,first,mid,last,temp); }}voidmergeArray(int a[],...
阅读全文
摘要:#include <stdio.h>#include <stdlib.h>void swap(int a[], int n, int i){ int temp; temp = a[n] ; a[n] = a[i] ; a[i] = temp;}void HeapAdjust(int L[], int s, int m){ int temp,j; temp = L[s]; for( j = 2*s; j<m; j*=2) { if(j < m && ...
阅读全文