数据结构
本科数据结构课程实验
杳杳_柒
为了理解递归,我们首先要理解的是递归
展开
-
21.逆波兰表达式
#include<stdio.h>#include<stdlib.h>typedef struct node{ char data; struct node *next;}node,*pnode;typedef struct stack{ struct node *bottom; struct node *top;}stack,*p...原创 2019-06-27 22:02:01 · 287 阅读 · 0 评论 -
22.Dijkstra算法
#include<stdio.h>#include<stdlib.h>#define inf 10000typedef struct{ int vexs[100]; int arc[100][100]; int vexnum,arcnum;}LGraph;int Getinfo(LGraph *G, int j){ for(int ...原创 2019-06-27 22:02:31 · 285 阅读 · 0 评论 -
23.构造哈希表
#include<stdio.h>#include<stdlib.h>typedef struct HashTableNode{ int data; int flag;}Node;Node *T[11];int DList[8]={22,41,53,46,30,13,01,67};void GetHashTable();Node *...原创 2019-06-27 22:02:43 · 1042 阅读 · 0 评论 -
24.二叉排序树的判别
#include<stdio.h>#include<stdlib.h>typedef struct BinaryTree{ int num; struct BinaryTree *lchild; struct BinaryTree *rchild;}BTree;void CreateBTree(BTree *List){ int n;...原创 2019-06-27 22:02:53 · 421 阅读 · 0 评论 -
25.二叉排序树的插入和删除
#include<stdio.h>#include<stdlib.h>typedef struct BinNode{ int data; struct BinNode *lchild; struct BinNode *rchild;}BinNode,*BinTree;void CreateBinTree(BinTree *tree){...原创 2019-06-27 22:03:21 · 839 阅读 · 0 评论 -
26.二叉排序树的合并
#include<stdio.h>#include<stdlib.h>typedef struct BinNode{ int data; struct BinNode *lchild; struct BinNode *rchild;}BinNode,*BinTree;void CreateBinTree(BinTree *tree){...原创 2019-06-27 22:03:31 · 738 阅读 · 0 评论 -
实验1.1 合并有序数组
#include <stdio.h>#include <stdlib.h>typedef struct Node{ int data; struct Node *next;}LNode,*p;void debugprint(LNode *p){ return ; for(; p; p=p->next) p...原创 2019-06-29 11:17:50 · 1050 阅读 · 0 评论 -
实验1.2 高精度计算PI值
/*#include<stdio.h>#include<stdlib.h>int k;typedef struct node { int data; struct node*next; struct node*pre;}node,*list;void init(list l){ list tail = l, p; p=(li...原创 2019-06-29 11:18:14 · 2379 阅读 · 4 评论 -
实验2.1 稀疏矩阵转置
#include<stdio.h>typedef struct{ int r; int c; int v;}Triple;int main(){ int m,n,i=0,j=0; scanf("%d%d",&m,&n); Triple A[130000]; for(;;) { int r...原创 2019-06-29 11:18:20 · 1904 阅读 · 1 评论 -
实验2.2 稀疏矩阵加法,实现C=A+B
#include <stdio.h>#include <stdlib.h>typedef struct node{ int r; int c; int v;}node;typedef struct{ int cnt1; int cnt2; node matrix1[1000]; node...原创 2019-06-29 11:18:28 · 1965 阅读 · 0 评论 -
实验2.3 稀疏矩阵加法,系数矩阵加法,用十字链表实现C=A+B
#include <stdio.h>#include <stdlib.h>typedef struct OLNode{ int r,c,v; struct OLNode *right,*down;}Node,*LNode;typedef struct{ LNode *Rhead,*Chead; int mu,n...原创 2019-06-29 11:18:40 · 1675 阅读 · 0 评论 -
实验2.4 稀疏矩阵的乘法
#include <stdio.h>#include <stdlib.h>template<typename T> int findX(T *a, int n, T b){ int l=0,r=n; int mid; do { mid = (l+r)/2; if(a[mid]<b || a[mid]==b) l = ...原创 2019-06-29 11:18:48 · 936 阅读 · 0 评论 -
实验3.1 哈夫曼/译码器
#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAXNODE 100#define MAXNUM 5000struct HtNode{ int weight; int parent,lchild,rchild;};typedef ...原创 2019-06-29 11:19:08 · 1127 阅读 · 0 评论 -
实验4.1 求赋权图中一个结点到所有结点的最短路径长度
#include<stdio.h>#define max 10000;int arcs[100][100]; //matrixint d[100]; //shortest distanceint fina[100]; //vertex judge,1 stand for yes(in s)int n; //edgeint v0 = 0; // vertex...原创 2019-06-29 11:19:17 · 1335 阅读 · 0 评论 -
实验4.2 用迪杰斯特拉算法求赋权图中的最短路径
#include<stdio.h>#define max 10000int arcs[100][100];//metrixint visited[100];//1 stand for yes ,0 stand for noint prev[100];//every point on the pathint d[100];//shortest pathint...原创 2019-06-29 11:19:24 · 1211 阅读 · 0 评论 -
实验4.3 用弗洛伊德算法求赋权图的两点间的最短路径的长度
#include<stdio.h>#define max 10000int n;//size of matrix int d[100][100];//length of the pathvoid Floyd(){ int i,j,k; for(i=0;i<n;i++) for(j=0;j<n;j++) for(k=0;k<n...原创 2019-06-29 11:19:31 · 864 阅读 · 0 评论 -
20.基于图的广度优先搜索策略
#include<stdio.h>#include<stdlib.h>#define max 200typedef struct data{ int num; struct data *next;}data;typedef struct queue{ struct data *head; struct data *rear;}qu...原创 2019-06-23 16:54:02 · 1174 阅读 · 0 评论 -
18.建立二叉树的二叉链表
#include<stdio.h>#include<stdlib.h>typedef struct BTNode{ char data; struct BTNode *lchild; struct BTNode *rchild;}BTNode;char pre[100],mid[100];int num;void init(){...原创 2019-06-23 16:53:12 · 527 阅读 · 0 评论 -
17.输出以二叉树表示的算术表达式
#include <stdio.h>#include <stdlib.h>typedef struct BTNode{ char data; struct BTNode *lchild; struct BTNode *rchild;}BTNode;BTNode *CreateTree(){ BTNode *root =(BTNode*...原创 2019-06-23 16:52:41 · 691 阅读 · 1 评论 -
2.线性表的就地逆置
#include<stdlib.h>#include<iostream>using namespace std;typedef struct node{ int num; node* next;}node;int n;int ray[1005]; void array(){ int i; cout<<ray[n-1...原创 2019-06-16 15:15:52 · 546 阅读 · 0 评论 -
1.顺序表的插入运算
#include<iostream>using namespace std; int main(){ int ary[1005]; int n,m,i,tmp,flag=0; cin>>n; for(i=0;i<n;i++){ cin>>ary[i]; } cin>>m; for(i=0;i<n-1;...原创 2019-06-16 15:21:13 · 788 阅读 · 0 评论 -
3.顺序表的删除
#include<stdio.h>#include<stdlib.h>void search(int A[100],int B[100],int C[100],int a,int b,int c){ int i=0,j=0,k=0,m,count=0; for(i=0; A[i];i++) { while( B[j] < A[i]...原创 2019-06-16 15:28:20 · 592 阅读 · 0 评论 -
4.单链表的归并
#include <stdio.h>#include <stdlib.h>typedef struct node{ int data; struct node *next;}LNode;LNode* CreateLinkList(int n){ LNode *head,*p,*q; int i; hea...原创 2019-06-16 15:32:44 · 347 阅读 · 0 评论 -
5.单链表的删除
#include <stdio.h>#include <stdlib.h>typedef struct node{ int data; struct node *next;}LNode;LNode* CreateLinkList(int n){ LNode *head,*p,*q; int i; hea...原创 2019-06-16 15:35:54 · 214 阅读 · 0 评论 -
6.LOCATE操作
#include<stdio.h>#include<stdlib.h>typedef struct list{ char s; int num; struct list *next,*pre;}list;list* init(){ list* head; head = (list* )malloc(sizeof(list)); he...原创 2019-06-16 15:38:38 · 403 阅读 · 0 评论 -
7.多项式括号匹配
#include<stdio.h>#include<stdlib.h>#define N 20#define SIZE 20#define MORE 10typedef struct{ char *base; char *top; int size;}STACK;void STACK_init(STACK *s, ...原创 2019-06-16 15:41:34 · 412 阅读 · 0 评论 -
8.逆波兰式
#include <stdio.h>#include <stdlib.h>#define Stack_Init_Size 20#define Stack_Increasement 10typedef char Elemtype;typedef struct{ Elemtype *base; Elemtype *top; i...原创 2019-06-16 15:43:16 · 321 阅读 · 0 评论 -
9.循环队列
/*#include<stdio.h>#include<stdlib.h>#define MAXIMUM 100#define DataType inttypedef struct SeqQueue{ DataType q[MAXIMUM]; int front,rear;}SeqQueue,*PSeqQueue;PSeqQ...原创 2019-06-16 15:45:36 · 280 阅读 · 0 评论 -
10.K阶斐波那契数列
#include <stdio.h>#include <stdlib.h>#include <string.h>#define max 100typedef struct SeqQueue{ int front; int rear; int q[max];}SeqQueue,*PSeqQueue;void...原创 2019-06-16 15:49:02 · 878 阅读 · 0 评论 -
11.循环右移
#include<stdio.h>int main(){ int i,n,k,temp; scanf("%d%d",&n,&k); int arr[100]; for(i=0;i<n;i++) { scanf("%d",&arr[i]); } while(k--) { temp=arr[n-1]; for(i...原创 2019-06-23 16:50:23 · 214 阅读 · 0 评论 -
12.以三元组表为存储结构实现矩阵相加
/*#include <stdio.h>#include <stdlib.h>typedef struct{ int row; int col; int num;}node;typedef struct{ node matrix1[100]; node matrix2[100]; int cnt1; int cnt2;}mat...原创 2019-06-23 16:50:54 · 823 阅读 · 0 评论 -
13.以十字链表为存储结构实现矩阵相加
/*#include<stdio.h>#include<stdlib.h>typedef struct OLNode{ int r,c,e; struct OLNode *right, *down;}OLNode,*OLink;typedef struct { OLink rhead[100], chead[100]; int ru,...原创 2019-06-23 16:51:22 · 326 阅读 · 0 评论 -
14.求广义表深度
#include<stdio.h>#include<stdlib.h>typedef char ElemType;typedef struct INode{ int tag; union { ElemType data; struct INode *head; }val; struct INode *tail;}GLNode;...原创 2019-06-23 16:51:35 · 377 阅读 · 0 评论 -
15.建立二叉树的二叉链表存储结构
#include<stdio.h>#include<stdlib.h>typedef struct BTNode{ char data; struct BTNode *lchild; struct BTNode *rchild;}BTNode;BTNode *CreateTree(){ char c1,c2; BTNode *q;...原创 2019-06-23 16:51:47 · 2406 阅读 · 0 评论 -
16.计算二叉树叶子节点数目
#include<stdio.h>#include<stdlib.h>typedef struct BTNode{ char data; struct BTNode *lchild; struct BTNode *rchild;}BTNode;BTNode *CreateTree(){ char s; BTNode *root = ...原创 2019-06-23 16:51:58 · 433 阅读 · 0 评论 -
19.基于图的深度优先搜索策略
#include<stdio.h>#include<stdlib.h>#define max 200typedef char VertexType;typedef struct AdjVNode *PtrToAdjVNode;typedef struct GNode *PtrToGNode;int visited[max]={0};typ...原创 2019-06-23 16:53:35 · 696 阅读 · 0 评论