├── 2011 ├── Five-1.cc └── Five-2.cc ├── 2012 ├── Five-1.cc ├── Five-2.cc └── Five-3.cc ├── 2013 ├── Six-1.cc └── Six-2.cc ├── 2014 └── Six.cc ├── 2015 ├── Six-1.cc ├── Six-2.cc └── Six-3.cc ├── .gitattributes ├── .gitignore └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /2011/Five-1.cc: -------------------------------------------------------------------------------- 1 | typedef struct LNode { 2 | int data; 3 | struct LNode *next; 4 | } *LinkList; 5 | 6 | void A7(LinkList L) { 7 | LNode *p, *q, *r, *u; 8 | p = L->next; 9 | L->next = NULL; 10 | while (p != NULL) { 11 | r = L; 12 | q = L->next; 13 | while (q != NULL && q->data <= p->data) { 14 | r = q; 15 | q = q->next; 16 | } 17 | u = p->next; 18 | p = p->next; 19 | r->next = p; 20 | p = u; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /2011/Five-2.cc: -------------------------------------------------------------------------------- 1 | typedef struct BiTNode { 2 | TelemType data; 3 | struct BiTNode *lchild, *rchild; 4 | } *BiTree; 5 | 6 | int depth[MaxSize]; 7 | 8 | void A8(BiTree T) { 9 | int front = 0, rear = 0; 10 | BTNode *que[MaxSize], *q; 11 | if (p != NULL) { 12 | rear = (rear + 1) % MaxSize; 13 | que[rear] = p; 14 | depth[rear] = 1; 15 | while (front != rear) { 16 | front = (front + 1) % MaxSize; 17 | q = que[front]; 18 | if (q->lchild != NULL) { 19 | rear = (rear + 1) % MaxSize; 20 | que[rear] = q->lchild; 21 | depth[rear] = depth[front] + 1; 22 | } 23 | if (q->rchild != NULL) { 24 | rear = (rear + 1) % MaxSize; 25 | que[rear] = q->rchild; 26 | depth[rear] = depth[front] + 1; 27 | } 28 | } 29 | } 30 | cout << "The depth is : " << depth[front] << endl; 31 | } 32 | 33 | 34 | void A8(BiTree T) { 35 | int front = 0, rear = 0; 36 | BTNode *que[MaxSize], *q; 37 | if (p != NULL) { 38 | rear = (rear + 1) % MaxSize; 39 | que[rear] = p; 40 | int depth = 1; 41 | while (front != rear) { 42 | front = (front + 1) % MaxSize; 43 | q = que[front]; 44 | if (q->lchild != NULL) { 45 | rear = (rear + 1) % MaxSize; 46 | que[rear] = q->lchild; 47 | } 48 | if (q->rchild != NULL) { 49 | rear = (rear + 1) % MaxSize; 50 | que[rear] = q->rchild; 51 | } 52 | if (front == high) { 53 | high = rear; 54 | depth++; 55 | } 56 | } 57 | } 58 | cout << "The depth is : " << depth[front] << endl; 59 | } 60 | -------------------------------------------------------------------------------- /2012/Five-1.cc: -------------------------------------------------------------------------------- 1 | // 2012 HDU Data Structure 2 | // Five-1 3 | 4 | typedef struct LNode { 5 | ElemType data; 6 | struct LNode *next; 7 | } LNode, *LinkList; 8 | 9 | bool Delete_x(LinkList &L, ElemType x) { 10 | LNode *r, *p; 11 | if (L->data == x) { 12 | r = L; 13 | L = L->next; 14 | free(r); 15 | return true; 16 | } 17 | p = L; 18 | while (p->next != NULL) { 19 | if (p->next->data == x) { 20 | r = p->next; 21 | p->next = p->next->next; 22 | free(r); 23 | return true; 24 | } 25 | } 26 | return false; 27 | } 28 | -------------------------------------------------------------------------------- /2012/Five-2.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambdacat94/HDUDS/66dcc245eb3acf85eb8e05a97ec5dccba7e0ca6b/2012/Five-2.cc -------------------------------------------------------------------------------- /2012/Five-3.cc: -------------------------------------------------------------------------------- 1 | // 2012 HDU Data Structure 2 | // Five-3 3 | 4 | typedef struct BiTNode { 5 | TElemType data; 6 | struct BiTNode *lchild, *rchild; 7 | } BiTNode, *BiTree; 8 | 9 | BiTNode *Next(BiTNode *p) { 10 | BiTNode *q = p->rchild; 11 | while (q->lchild != NULL) 12 | q = q->lchild; 13 | return q; 14 | } 15 | -------------------------------------------------------------------------------- /2013/Six-1.cc: -------------------------------------------------------------------------------- 1 | typedef struct LNode { 2 | ElemType data; 3 | struct LNode *next; 4 | } LNode, *LinkList; 5 | 6 | void Diff(LinkList &L1, LinkList L2) { 7 | LNode *p = L1->next, pre = L1; 8 | while (p != NULL) { 9 | LNode *q = L2->next; 10 | while (q != NULL) { 11 | if (p->data == q->data) { 12 | pre->next = p->next; 13 | free(p); 14 | p = pre->next; 15 | } 16 | else { 17 | q = q->next; 18 | } 19 | } 20 | pre = p; 21 | p = p->next; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /2013/Six-2.cc: -------------------------------------------------------------------------------- 1 | typedef struct CTNode { 2 | int child; 3 | struct CTNode *next; 4 | } *ChildPtr; 5 | 6 | typedef struct { 7 | ElemType data; 8 | ChildPtr firstchild; 9 | } CTBox; 10 | 11 | typedef struct { 12 | CTBox nodes[MAX_TREE_SIZE]; 13 | int n, r; 14 | } CTree; 15 | 16 | void POTT(CTree &T, int v, void(*visit)(ElemType e)) { 17 | ChildPtr p = T.nodes[v].firstchild; 18 | visit(T.nodes[v].data); 19 | while (p != NULL) { 20 | POTT(T, p->child, visit); 21 | p = p->next; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /2014/Six.cc: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /2015/Six-1.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambdacat94/HDUDS/66dcc245eb3acf85eb8e05a97ec5dccba7e0ca6b/2015/Six-1.cc -------------------------------------------------------------------------------- /2015/Six-2.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambdacat94/HDUDS/66dcc245eb3acf85eb8e05a97ec5dccba7e0ca6b/2015/Six-2.cc -------------------------------------------------------------------------------- /2015/Six-3.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambdacat94/HDUDS/66dcc245eb3acf85eb8e05a97ec5dccba7e0ca6b/2015/Six-3.cc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HDU_DS 2 | HDU_DataStructure_Code 3 | 4 | 杭州电子科技大学 2011——2015 专业课《数据结构》的最后算法代码部分。 5 | 6 | 一些算法的代码可能还不完美符合考试的书写要求,目前还缺少 2014 年的代码,我会找时间添加。 7 | 8 | HDU 的《数据结构》科目难度并不大,考察相对基础,只要熟练掌握线性表、图、树以及查找结构的算法,例如: 9 | 10 | 1.线性表的遍历写法 11 | 12 | 2.树的递归遍历写法 13 | 14 | 3.图的深度优先于广度优先算法 15 | 16 | 再加上少许的变动改进,就足够应付考试的要求。 17 | 18 | 祝我及同考杭州电子科技大学的同学们考研成功! 19 | 20 | --------------------------------------------------------------------------------