- 博客(15)
- 收藏
- 关注
原创 C语言实现快速排序
快速排序采用的是分治的思想,即将数组从中间分成两部分,然后找出一个指定元素,比指定元素小的放左边;比指定元素大的放右边。 #include <bits/stdc++.h> using namespace std; void swapp(int *x,int *y) { int t=*x; *x=*y; *y=t; } //用分治的思想将数组分成两份 int fenzhi(int *a,int left,int right) { int j=left;//
2021-08-24 15:01:14
280
原创 C语言实现冒泡排序
#include <bits/stdc++.h> using namespace std; //冒泡排序 void bubblesort(int *a,int n) { for(int i=0;i<n-1;i++) { for(int j=0;j<n-1-i;j++) { //如果前面的数比后面的大,则进行交换 if(a[j]>a[j+1]) { .
2021-08-24 14:39:14
139
原创 C语言实现拓扑排序
#include <bits/stdc++.h> //#define ERROR 0 //#define OK 1 #define FALSE 0 #define TRUE 1 #define Mdingdian 99 //首先我有三个结构体 using namespace std; typedef int Boolean;//设置一个布尔值,这样就可以用到上面定义的true和false了 //typedef int VertexType;//顶点信息 Boolean visit[Mding.
2021-08-24 14:14:35
301
原创 C语言实现停车系统
#include <bits/stdc++.h> using namespace std; #define stacksize 10 typedef struct sqstack { int data[stacksize];//数组存储的是车辆信息 int top; }SqStackTp; typedef struct queue//定义队列结点的数据结构 { int data; struct queue *next; }LqueueTp; typede.
2021-08-24 14:12:17
356
原创 C语言实现还原二叉树
#include <stdio.h> #include <stdlib.h> typedef struct node { char data; struct node *lchild,*rchild; }no;//定义一个结构体 no *xianhezhong(char xianxu[],char zhongxu[],int n)//利用先序和中序建立二叉树 { char lxian[100],rxian[100],lzhong[100],rzhong[.
2021-08-24 14:10:54
516
原创 C语言实现报数问题(约瑟夫环)
#include <bits/stdc++.h> using namespace std; typedef struct kid { int data;//这个表示的是个人的编好以及在队列里的状态(即在还是不在) struct kid *next; }kids; typedef kids* p;//我写这个是为了同时定义多个结构体指针 p creat(int n) { p head,pre;//定义头结点和前驱以及后继指针 head=(p)malloc(.
2021-08-24 14:09:25
534
原创 C语言实现二叉排序树(采用递归思想)
#include <bits/stdc++.h> using namespace std; //这里是采用了递归的方法 typedef struct node { int data; struct node *lchild,*rchild; }bnode,*btree; void intree(btree <ree,int x) { if(ltree==NULL) { ltree=new bnode;//生成树的结点 .
2021-08-24 13:31:43
237
原创 C语言实现栈的建立和出入栈
#include <bits/stdc++.h> #define maxsize 100 using namespace std; typedef struct node { int data[maxsize]; int top;//有一个指针top来记录栈里数据的总数 }no,*lstack; lstack initstack(lstack p)//之所以用结构体指针来定义函数只是因为比较方便, { //因为栈内要有一个指向.
2021-08-24 13:19:23
314
原创 C语言实现循环队列
1.首先要先明白几个概念: 队首(front):允许进行删除的一端称为队首。 队尾(rear):允许进行插入的一端称为队尾。 2.当进队的时候,rear指针是向后运动的; 当出队的时候,front指针也是向后运动的; 因此这样经过一系列的操作后,两个指针最终会到达数组的末端处,虽然队中已没有了数据,但是仍然无法插入元素,这就是所谓的“假溢出”。为了解决假溢出的问题,可以将数组弄成一个环状,让rear和front指针沿着环走,这样就不会出现无法继续走下去的情况,这样就产生了循环队列。4 ...
2021-08-23 21:16:20
352
原创 C语言实现二叉树的建立(一般用前序建立)
#include <bits/stdc++.h> using namespace std; typedef struct treenode { char val;//结点 struct treenode *left;//建立左指针 struct treenode *right;//建立右指针 }tno,*t_pointer; void buildtree(t_pointer &t)//建立二叉树 { char ch; cin>>.
2021-08-21 19:38:03
812
原创 C语言实现单链表指定结点的插入
#include <bits/stdc++.h> using namespace std; typedef struct node { int data; struct node *next; }no; int main() { no *head,*tail,*p,*q; head=new no; head->next=NULL; tail=head; int n; printf("一共要输入的数:"); ci.
2021-07-26 14:00:54
899
原创 C语言实现单链表删除指定结点
#include <bits/stdc++.h> using namespace std; typedef struct node { int data; struct node *next; }no; int main() { no *head,*tail,*p,*r,*q; head=new no; head->next=NULL; tail=head; int n,k; printf("一共要输入的数: ");..
2021-07-25 14:22:01
6982
3
原创 C语言实现头插法建立单链表
首先要明确一点,利用头插法建立出来的单链表的输出都是逆序的(就是和你的输入顺序反着来的)然后就是要明确生成的新结点是一个个加在头结点的前面的,这就是头插法。至于怎么将结点一个个插入在头结点前面呢?下面的图可以比较详细的展示出来(至少对我来说挺详细的哈) p->next=head->next; //一开始 head->next=NULL; head->next=p;//然后将p指针指向head结点指向的下一个结点 以下是图像展示: #include &...
2021-07-21 22:16:15
4658
1
原创 C语言体现数据结构中的尾插法
#include <bits/stdc++.h> //尾插法输出的数都是顺序的 using namespace std; typedef struct node { int data;//数据域,存储数据 struct node *next;//指针域,存储指针,存放后继结点信息 }no; //这里的尾插法将tail作为可移动的指针,p也是可移动的, //p它是用于生成新的结点,同时记得给新结点赋值哦,并且在生成完链表之后,遍历一个个结点并输出 //生成链表 int ...
2021-07-20 13:55:59
502
原创 尾插法建立单链表 数据结构
尾插法建立链表 一、链表是什么? 链表是一种常见的基础数据结构,并且充分的利用到了结构体指针。可以将链表看成一种功能强大的数组,可以在节点中定义多种数据类型,可以随意添加、删除和插入节点。链表都有一个头指针,一般以head来表示,存放的是一个地址。链表中的节点分为两类,头结点和一般节点,头结点是没有数据域的。链表中每个节点都分为两部分,一个数据域,一个是指针域。 二、代码 #include <bits/stdc++.h> using namespace std; //区分尾插还是头插的方法就是看
2021-01-19 22:45:24
1916
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人