随笔分类 - 数据结构
摘要:template<class Elem>class HuffNode{public: virtual int weight()=0; virtual bool isLeaf()=0; virtual HuffNode* left() const=0; virtual void setLeft(HuffNode*)=0; virtual HuffNode* right() const=0; virtual void setRight(HuffNode*)=0;};template<class Elem>class LeafNode:public HuffNod...
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#define MAXSIZE 50#define ERROR -1#define OK 0#define FALSE 0#define TRUE 1typedef enum{RIGHT,DOWN,LEFT,UP}Direction;typedef enum{YES,NO}MarkTag;typedef struct position{ int x;int y;}Position;typedef struct{ int order; Position seat; Direction di;}SElem
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#define CLOSETIME 1000#define M 3typedef struct QueueNode{ int arrivetime; int duration; struct QueueNode *next;}QueueNode;typedef struct QueueHeader{ QueueNode *front,*rear; int length;}QueueHeader;typedef struct EventNode{ int occurTime,eventTyp...
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#include<string.h>#define INF "in.txt"typedef struct Node{ char *word; int count; struct Node *left,*right;}Node,*BiTree;int searchBst(BiTree T,char *keyword,BiTree *p){ int cmpres=0; BiTree ptr; *p=NULL;ptr=T; while(ptr) { cmpres=str...
阅读全文
摘要:#include "BinaryNode.h"#include "Dictionary.h"template <class Key,class Elem,class KEComp,class EEComp>class BST :public Dictionary<Key,Elem,KEComp,EEComp>{private: BinNode<Elem>* root; int nodecount; void clearhelp(BinNode<Elem>*); BinNode<Elem>* in
阅读全文
摘要:template <class Elem> //单链表class Link{public: Elem element; Link *next; Link(const Elem& elemval,link *nextval=NULL) { element=elemval; next=nextval; } Link(Link * nextval=NULL) { next=nextval; }};template <class Elem> class LList:public List<Elem>{private: ...
阅读全文
摘要:template<class Elem>//用数组实现的队列class AQueue:public Queue<Elem>{private: int size; int front; int rear; Elem *listArray;public: AQueue(int sz=DefaultListSize) { size=sz+1; rear=0;front=1; listArray=new Elem[size]; } ~AQueue() { delete [] listArray...
阅读全文
摘要:template<class Elem>class AStack:public Stack<Elem> //数组实现的栈类{private: int size; int top; Elem *listArray;public: AStack(int sz=DefaultListSize) { size=sz;top=0;listArray=new Elem[sz]; } ~AStack() { delete [] listArray; } void clear() { top...
阅读全文
摘要:template<class Elem,class Comp>//Insertion Sortvoid inssort(Elem A[],int n){ for(int i=1;i<n;i++) for(int j=i;(j>0)&&(Comp::lt(A[j],A[j-1]));j--) swap(A,j,j-1);}//Bubble Sorttemplate<class Elem,class Comp>void bubsort(Elem A[],int n){ for(int i=0;i<n-1;i++) for(int j=n..
阅读全文
摘要:#include "LList.h"#define UNVISITED 0//A graph ADTclass Graph{public: virtual int n()=0; virtual int e()=0; virtual int first(int)=0; virtual int next(int,int)=0; virtual int setEdge(int ,int,int)=0; virtual int delEdge(int,int)=0; virtual int weight(int ,int)=0; virtual int...
阅读全文
摘要:#include <stdio.h>#include<stdlib.h>#define MaxN 6int visited[MaxN]={0};typedef struct ArcNode{ int adjvex; double weight; struct ArcNode *nextarc;}EdgeNode;typedef struct VNode{ char data; struct ArcNode *firstarc;}AdjList[MaxN];typedef struct Graph{ int Vnum; AdjList Vertices;...
阅读全文

浙公网安备 33010602011771号