DSAAC习题
孑然夏石
这个作者很懒,什么都没留下…
展开
-
二叉树的实现
#include <stdio.h>#include <stdlib.h>struct TreeNode;typedef struct TreeNode* Position;typedef struct TreeNode* SearchTree;SearchTree MakeEmpty(SearchTree T);Position Find(int x, SearchTree T);Position FindMin(SearchTree T);Position .原创 2022-01-27 16:19:00 · 56 阅读 · 0 评论 -
DSAAC第三章课后习题前几题
//3.1 打印List Lvoid print_list(List L){ Position p = L->next; while (p->next != NULL) printf(p->data);}//3.2 根据List P打印List Lvoid PrintLots(List L, List P){ int dif = P->data, counter; while (P->next != NULL&&L->nex.原创 2022-01-27 11:21:37 · 876 阅读 · 0 评论 -
图的存储/DFS/BFS(自己写的)
#include <stdio.h>#include <stdlib.h>#define max 10typedef int VertexType;typedef int WeightType;struct am_graph{ VertexType vexs[max];//顶点表 WeightType edges[max][max];//邻接矩阵 int vex_num, arcnum;//顶点、边数};typedef struct am_graph* A.原创 2021-10-15 15:30:45 · 104 阅读 · 0 评论 -
自动生成1-100单向链表(多练习几遍)
#include <stdio.h>#include <stdlib.h>struct node { int data; struct node* next;};typedef struct node* list;typedef struct node* position;position attatch(position p, int x){ position new = malloc(sizeof(struct node)); new->data.原创 2021-09-24 17:34:47 · 176 阅读 · 0 评论 -
DSAAC Stack的两种实现方法
#ifndef _stack_h_linked_liststruct node;typedef struct node* ptrnode;typedef ptrnode stack;int is_empty(stack s);stack create_stack(void);void dispose_stack(stack s);void make_empty(stack s);void push(int x, stack s);int top(stack s);void pop(.原创 2021-09-22 22:03:07 · 60 阅读 · 0 评论 -
一、DSAAC 链表的实现
#include <stdio.h>#ifndef _List_Hstruct Node;typedef struct Node* PtrToNode;typedef PtrToNode List;typedef PtrToNode Position;List make_empty(List l);int is_empty(List l);int is_last(Position p, List l);Position Find1(int x, List l);Pos.原创 2021-09-18 10:19:11 · 90 阅读 · 0 评论 -
DSAAC习题3.25 数组实现队列的完整操作集
#ifndef _queue_hstruct queue_node;typedef struct queue_node* queue;int is_empty(queue Q);int is_full(queue Q);queue create_queue(int MaxElements);void dispose_queue(queue Q); void make_empty(queue Q); void enqueue(queue Q, int X);void dequeue(.原创 2021-09-25 16:10:29 · 66 阅读 · 0 评论 -
DSAAC习题3.21 一个数组实现2个stack
/*implement 2 stacks by 1 array*/#include <stdio.h>#include <stdlib.h>#define max 20struct stack_node { int top_left; int top_right; int* a;};typedef struct stack_node* stack;void make_empty(stack s){ s->top_left = -1; s->.原创 2021-09-25 11:48:01 · 54 阅读 · 0 评论 -
DSAAC习题3.12 倒转链表
用stack确实方便;先布置好开头再一直while也很方便,就是有点难想。/* reverse a singly linked list */#include <stdio.h>#include <stdlib.h>struct node { int data; struct node* next;};typedef struct node* list;typedef struct node* position;position attatch(posi原创 2021-09-25 11:00:38 · 60 阅读 · 0 评论 -
DSAAC习题3.11 对递归的理解!!(学到了,学到了)
重点看find_recur(list l, int x)函数,理解递归。/*find a particular element*/#include <stdio.h>#include <stdlib.h>struct node { int data; struct node* next;};typedef struct node* list;typedef struct node* pos;pos find_non_recur(list l.原创 2021-09-24 16:19:56 · 63 阅读 · 0 评论 -
DSAAC习题3.10 约瑟夫环问题(击鼓传花)(未成功)
玩家数和传递击鼓次数m,n对于一定的数字组合无法运行,有的时候时access violat。目前只能感觉是底层包括堆栈的问题,等学过硬件知识要回头看。/*击鼓传花, Josephus*//*其实单链表也能做,反正都是一个方向传*//*只不过有指针pre更好做*/#include <stdio.h>#include <stdlib.h>struct node { int num; struct node* next; struct node* pre;};t原创 2021-09-24 15:13:58 · 150 阅读 · 0 评论 -
DSAAC习题3.6
/*默认header和NULL*//*默认数据输入是次数从高到底排序*/#include <stdio.h>#include <stdlib.h>struct node { int coef; int exp; struct node* next;};typedef struct node* term;typedef struct node* poly;void insert(int c, int e, term p){ term temp = mal.原创 2021-09-24 10:54:30 · 55 阅读 · 0 评论 -
DSAAC习题3.4和3.5
/*默认有header*//*FOR singly Linked Lists*//*swap two adjcent elements*/#include <stdio.h>typedef struct lnode* list;typedef struct lnode* position;struct lnode { int data; struct lnode* next;};void finish(position p){ p->next = NULL;}.原创 2021-09-23 17:32:33 · 53 阅读 · 0 评论 -
DSAAC习题 3.3
/*默认有header*//*FOR singly Linked Lists*//*swap two adjcent elements*/#include <stdio.h>typedef struct lnode* list;typedef struct lnode* position;struct lnode { int data; struct lnode* next;};position find_precell_by_pos(list l,position po.原创 2021-09-23 15:29:37 · 72 阅读 · 0 评论 -
DSAAC习题3.2
#include <stdio.h>/*习题3.2,这里我们认为有header*/typedef struct lnode* ptrnode;typedef ptrnode list;typedef ptrnode position;struct lnode { int data; struct lnode* next;};/*这是倒着插进去的*/void insert(int x, list positon){ list temp = malloc(sizeof(s.原创 2021-09-23 11:36:07 · 62 阅读 · 0 评论