//2022.9.6数据结构作业#include <stdio.h>#include <stdlib.h>#define N 20typedef struct sqlist{ int *elem; //基地址 int length; //表长 int listsize; //存储空间大小}sql;//定义一个变量(顺序表)sql L;//初始化void InitList(){ L.elem=(int *)malloc(N*sizeof(int)); //申请存储空间 if(!L.elem) exit(0); //判断是否申请成功 L.listsize=N; //空间大小 L.length=0; //空间长度}//输入void input(int n){ int i; for(i=0;i<n;i++) scanf("%d",&L.elem[i]); L.length=n;}//输出void outp ...
//2022.9.16作业,链式表取元素#include <stdio.h>#include <stdlib.h>typedef struct link{ int data;//代表数据域 struct link *next;//代表指针域,指向后继元素}link;//link为节点名,每个节点都是一个link结构体//定义头指针link *L;//初始化链表void Initlink(){ L=(link*)malloc(sizeof(link));//创建首元节点 L->next=NULL;//创建头指针}//创建单链表void creatlink(int n){ link *p; Initlink(); int i; for(i=1;i<=n;i++){ p=(link*)malloc(sizeof(link)); scanf("%d",&p->data); p->next=L->next; L->next=p; } ...
//2022.9.16双向链表#include<stdio.h>#include<stdlib.h>typedef struct dlink{ int data;//代表数据域 struct dlink *prior,*next;//prior代表前驱,next代表后继}dlink;//双链表节点名dlink *L;//初始化链表void initlink(){ L=(dlink *)malloc(sizeof(dlink)); L->next=NULL; L->prior=NULL;}//创建双向链表void creatlink(int n){ dlink *p; initlink(); int i; for(i=1;i<=n;i++){ p=(dlink*)malloc(sizeof(dlink)); scanf("%d",&p->data); p->next=L->next; L->next=p; p->prio ...
#include<stdio.h>#define N 100#define HUGE 100//定义哈夫曼树的结点类型typedef struct hnode { int weight; //权值 int parent; //双亲 int lchild; //左孩子 int rchild; //右孩子}hnode;hnode h[N]; //存放所有节点int w[N] = { 0 }; //存放权值//输入叶子结点的个数和权值int n, m;void input() { printf("请输入叶子的个数:"); scanf("%d", &m); printf("请输入%d个叶子结点的权值:", m); for (int i = 0; i < m; i++) scanf("%d", &w[i]); n = 2 * m - 1; //所有节点的个数}//初始化,说明void init() { f ...
//2022.9.28 回文的实现(数值)#include <stdio.h>#include <stdlib.h>#include <math.h>//定义单链表节点类型typedef struct qlink { int data; //数据域 struct qlink* next;//指针域}qlink;//定义链队列的类型typedef struct linkqueue { qlink* front;//队头指针 qlink* rear;//队尾指针}linkq;linkq q;//定义一个链队列//初始化链队列void initqlink() { q.front = (qlink*)malloc(sizeof(qlink)); if (!q.front) exit(0); q.front->next = NULL; q.rear = q.front;//空队列}//入队(插入)void enqlink(int e) { qlink* p; p = (qlink* ...
//2022.9.28 回文的实现(字符)#include <stdio.h>#include <stdlib.h>#include <string.h>//定义单链表节点类型typedef struct qlink { int data; //数据域 struct qlink* next;//指针域}qlink;//定义链队列的类型typedef struct linkqueue { qlink* front;//队头指针 qlink* rear;//队尾指针}linkq;linkq q;//定义一个链队列//初始化链队列void initqlink() { q.front = (qlink*)malloc(sizeof(qlink)); if (!q.front) exit(0); q.front->next = NULL; q.rear = q.front;//空队列}//入队(插入)void enqlink(char e) { qlink* p; p = (qli ...
//2022.9.28 建立多个正序单链表并合并 #include<stdio.h>#include<stdlib.h>typedef struct node { int data; struct node* next;}node;node* initlist() { node* l, * t; l = (node*)malloc(sizeof(node)); if (!l) exit(0); l->next = NULL; t = l; return l;//返回头指针}//创建链表void creat(node* l, int n) { node* p, * t; t = l; int i; for (i = 1; i <= n; i++) { p = (node*)malloc(sizeof(node)); if (!p) exit(0); scanf("%d", &p->data); p->next = NULL; t-> ...
//2022.9.28 建立多个正序单链表并合并 #include<stdio.h>#include<stdlib.h>typedef struct node { int data; struct node* next;}node;node* initlist() { node* l, * t; l = (node*)malloc(sizeof(node)); if (!l) exit(0); l->next = NULL; t = l; return l;//返回头指针}//创建链表void creat(node* l, int n) { node* p, * t; t = l; int i; for (i = 1; i <= n; i++) { p = (node*)malloc(sizeof(node)); if (!p) exit(0); scanf("%d", &p->data); p->next = NULL; t-> ...
//2022.9.30循环队列#include <stdio.h>#include <stdlib.h>#define N 20//定义顺序队列的类型typedef struct sqque{ int *base;//基地址 int front;//队头指针(下标) int rear;//队尾指针(下表)}sqq;//定义一个顺序队列sqq q;void initque(){ q.base=(int *)malloc(N*sizeof(int)); if(!q.base) exit(); q.front=q.rear=0;//空队列}//入队void enque(int e){ if(q.front==(q.rear+1)%N) { exit(0); } q.base[q.rear]=e;//元素的插入 q.rear=(q.rear+1)%N;//修改的队尾指针}//出队void delque(){ int e; if(q.base==q.rear) { e ...
//2020.9.23栈#include <stdio.h>#include <stdlib.h>#define N 20//定义顺序栈的类型typedef struct sqstack{ int *base; //栈底指针 int *top; //栈顶指针 int stacksize; //存储空间大小}sqs;sqs s; //定义一个顺序栈//初始化void initstack(){ s.base=(int *)malloc(N*sizeof(int)); if(!s.base) exit(0); s.top=s.base; //空栈 s.stacksize=N;}//入栈(插入元素)void push(int e){ if(s.top-s.base>=s.stacksize){ printf("栈满\n"); exit(0); /*s.base=(int *)realloc(s.base,(N+M)*sizeof(int)) if(!s.base) ...