随笔分类 -  数据结构

摘要: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... 阅读全文
posted @ 2012-02-16 19:03 苍术厚朴 阅读(354) 评论(0) 推荐(0)
摘要:#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 阅读全文
posted @ 2012-02-16 19:00 苍术厚朴 阅读(275) 评论(0) 推荐(0)
摘要:#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... 阅读全文
posted @ 2012-02-16 18:59 苍术厚朴 阅读(304) 评论(0) 推荐(0)
摘要:#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... 阅读全文
posted @ 2012-02-16 18:58 苍术厚朴 阅读(335) 评论(0) 推荐(0)
摘要:#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 阅读全文
posted @ 2012-02-16 18:54 苍术厚朴 阅读(482) 评论(0) 推荐(0)
摘要: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: ... 阅读全文
posted @ 2012-02-16 18:52 苍术厚朴 阅读(356) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2012-02-16 18:50 苍术厚朴 阅读(225) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2012-02-16 18:45 苍术厚朴 阅读(260) 评论(0) 推荐(0)
摘要: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.. 阅读全文
posted @ 2012-02-16 18:41 苍术厚朴 阅读(392) 评论(0) 推荐(0)
摘要:#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... 阅读全文
posted @ 2012-02-16 18:39 苍术厚朴 阅读(336) 评论(0) 推荐(0)
摘要:#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;... 阅读全文
posted @ 2012-02-16 18:37 苍术厚朴 阅读(265) 评论(0) 推荐(0)