![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构练习
文豪必上岸
这个作者很懒,什么都没留下…
展开
-
邻接矩阵的迪杰斯特拉(dijkstra)
#include<stdio.h>#include<stdlib.h>#define INF 9999999#define MaxSize 50typedef struct{ char vex[MaxSize]; int edge[MaxSize][MaxSize]; int vexnum,arcnum;}MGraph;void Dijkstra(MGraph G,int v,int dist[],int path[]){ int final[MaxSize].原创 2021-12-03 13:15:23 · 482 阅读 · 0 评论 -
存入二叉树的算术表达式的遍历求值
思路是后续遍历二叉树(也就是后最表达式)遍历到一个元素时存入到栈里一个,如果遇到符号就弹出当前的两个栈顶元素和符号运算,求出值再插入栈中,知道最后一个元素就是算数表达式的值。#include<stdio.h>#include<stdlib.h>#define MaxSize 50typedef struct{ char data[MaxSize]; int top;}Sqstack;void InitStack(Sqstack &s){ s.top=-原创 2021-11-21 04:23:51 · 450 阅读 · 0 评论 -
8.4选择排序综合应用5
#include<stdio.h>#include<stdlib.h>#include<math.h>bool If(int A[],int n){ int i,j; if(A[0]>A[1] || A[0]>A[2]) return false; for(i=n/2-1;i>0;i--){ for(j=2*i;j<=n-1;j=j*2){ if(A[j+1]<A[j] && j+1<=n-.原创 2021-10-26 17:50:07 · 51 阅读 · 0 评论 -
8.4选择排序综合应用4
#include<stdio.h>#include<stdlib.h>typedef struct LNode{ int data; struct LNode *next;}LNode,*LinkList;void Insert(LinkList &L){ LNode *s; int x; L=(LinkList)malloc(sizeof(LNode)); //头指针 L->next=NULL; scanf("%d",&x); whi.原创 2021-10-26 16:05:54 · 52 阅读 · 0 评论 -
8.4选择排序2
#include<stdio.h>#include<stdlib.h>#include<math.h>void jj(int A[],int i,int num){ int temp=A[i],temp2; for(int j=2*i;j<=num-1;j=j*2){ if(A[j+1]<A[j] &&j<=num-2){ j++; } if(A[j]<temp){ temp2=A[j]; .原创 2021-10-24 20:51:18 · 52 阅读 · 0 评论 -
归并排序
#include<stdio.h>#include<stdlib.h>#include<math.h>void merge(int A[],int low,int mid,int high){ int *B=(int *)malloc((high+1)*sizeof(int)); int i,j,k; for(int s=0;s<=high;s++){ B[s]=A[s]; } for(i=low,j=mid+1,k=i;i<=mid&.原创 2021-10-23 01:49:45 · 48 阅读 · 0 评论 -
选择排序--推排序
#include<stdio.h>#include<stdlib.h>#include<math.h>void headAdjust(int A[],int i,int n){ int temp,temp2; temp=A[i]; for(int j=2*i;j<n-1;j=j*2){ if(j<=n-1 && A[j]<A[j+1]){ j++; } if(temp<A[j]){ .原创 2021-10-22 22:50:35 · 42 阅读 · 0 评论 -
选择排序--简单选择排序
#include<stdio.h>#include<stdlib.h>#include<math.h>void SelectSort(int A[],int n){ for(int i=n-1;i>=0;i--){ int temp; for(int j=i-1;j>=0;j--){ if(A[j]>A[i]){ temp=A[j]; A[j]=A[i]; A[i]=temp; } } }}.原创 2021-10-22 20:44:30 · 59 阅读 · 0 评论 -
交换排序--快速排序
#include<stdio.h>#include<stdlib.h>#include<math.h>int partition(int A[],int low,int high){ int pivot=A[low]; while(low<high){ while(low<high&&A[high]>=pivot) high--; A[low]=A[high]; while(low<high&.原创 2021-10-22 20:32:15 · 51 阅读 · 0 评论 -
交换排序--冒泡排序
#include<stdio.h>#include<stdlib.h>#include<math.h>void BubbleSort(int A[],int n){ int temp; for(int i=0;i<=n-1;i++){ for(int j=n-1;j>i;j--){ if(A[j-1]>A[j]){ temp=A[j-1]; A[j-1]=A[j]; A[j]=temp; } } .原创 2021-10-22 19:21:10 · 44 阅读 · 0 评论 -
希尔排序
#include<stdio.h>#include<stdlib.h>#include<math.h>void ShellSort(int A[],int n){ int d,i,j,temp; for(d=n/2;d>=1;d=d/2){ for(i=d;i<=n;i++){ if(A[i]<A[i-d]){ temp=A[i]; for(j=i-d;j>=0 && A[j]>temp;.原创 2021-10-22 00:02:39 · 38 阅读 · 0 评论 -
直接插入排序(折半查找法)
#include<stdio.h>#include<stdlib.h>#include<math.h>void InsertSort(int A[],int n){ int j,i,temp,low,high,mid; for(i=1;i<=n;i++){ temp=A[i]; low=0; high=i-1; while(low<=high){ mid=(low+high)/2; if(A[mid]<=temp).原创 2021-10-21 23:21:42 · 212 阅读 · 0 评论 -
直接插入排序
#include<stdio.h>#include<stdlib.h>#include<math.h>void InsertSort(int A[],int n){ int j,i,temp; for(i=2;i<=n;i++){ if(A[i]<A[i-1]){ temp=A[i]; for(j=i-1;A[j]>temp && j>=0;j--){ A[j+1]=A[j]; } A.原创 2021-10-19 21:56:30 · 40 阅读 · 0 评论 -
数据结构——链栈
#include<stdio.h>#include<stdlib.h>typedef struct LNode{ int data; struct LNode* next;}LNode,*SqStack;bool InitStack(SqStack &p){ p = (LNode*)malloc(sizeof(LNode)); p->next = NULL; return true;}bool Push(SqStack &p,int .原创 2021-08-15 18:31:20 · 66 阅读 · 0 评论 -
数据结构——单链表(带头指针)
#include<stdio.h>#include<stdlib.h>//typedef 改名typedef struct LNode{ int data; struct LNode *next;}LNode,*LinkList; //单链表找到头指针 就等于找到了链表bool InitList(LinkList &L){ L = (LNode *)malloc(sizeof(LNode)); if(L==NULL) .原创 2021-08-15 17:56:13 · 594 阅读 · 1 评论 -
用栈解决——括号配对
栈部分的代码#include<stdio.h>#include<stdlib.h>#define MaxSize 100typedef struct SqStack{ char data[MaxSize]; int top;}brackets;void InitStack(brackets *p){ p->top = -1; }bool Push(brackets *p,char x){ if(p->top == MaxSize-1)原创 2021-08-14 21:27:30 · 58 阅读 · 0 评论 -
数据结构——顺序栈
#include<stdio.h>#include<stdlib.h>#define MaxSize 10//定义结构体typedef struct SqStack{ char data[MaxSize]; int top;}SqStack;//初始化栈void InitStack(SqStack *p){ p->top = -1; }//入栈bool Push(SqStack *p,char x){ if(p->top == Ma原创 2021-08-14 15:17:23 · 61 阅读 · 0 评论