数据结构与算法
来源:互联网 发布:淘宝店怎么打造爆款 编辑:程序博客网 时间:2024/06/08 01:14
满二叉树:除最后一层外,每一层上的所有结点都有两个子结点。
完全二叉树:除最后一层外,每一层上的结点数均达到最大值,在最后一层上只缺少右边的若干结点。
链表的应用:
#include<stdio.h>
struct student{
int num;
float score;
struct Student *next;
}
void main(){
struct Student a,b,c,*head,*p;
a.num=10101;a.score=89.5;
b .num=10102;a.score=99.5;
c.num=10103;a.score=100;
head=&a;
a.next=&b;
b.next=&c;
c.next=null;
p=head;
do{
printf("%ld %5.lf\n,p->num,p->score")
p=p->next;
}while(p!=null);
}
二叉树的遍历:
前序遍历:先遍历根结点,然后遍历左子树,最后遍历右子树。ABDHECFG
中序遍历:先遍历左子树,然后遍历根结点,最后遍历右子树。HDBEAFCG
后根序遍历:先遍历左子树,然后遍历右子树,最后遍历根节点。HDEBFGCA
查找算法:
顺序查找:
二分法查找:
排序算法:
冒泡排序:
快速排序:
插入类排序:
选择类排序:
任意一棵二叉树度数为0的叶子结点总是比度数为2的结点多一个。
在线性表的链式存储结构中,各数据结点的存储序号是不连续的,并且个节点在存储空间中的位置关系和逻辑关系也不一致。
队列的顺序存储结构一般采用循环队列的形式
删除线性表中的数字方法:2.交替扫描,1.一步到位
#include <stdio.h>typedef char datatype;typedef struct {datatype data[10];int n;}sqlist;void init(sqlist *p) {int i, j;for (i = 97, j = 0; i < 108, j<7; i++, j++) {p->data[j] = i;}p->data[7] = 49;p->data[8] = 52;p->data[9] = 53;p->n = 10;printf("初始线性表为: ");for (j = 0; j < 10; j++) {printf("%c ", p->data[j]);}printf("\n");}void delect1(sqlist *p) {int n;n= p->n;int s = 0;int i;if (n == 0) {printf("下溢\n");return;}for (i = 0; i<n; i++) {if (p->data[i]>=48&&p->data[i]<=57) {s++;}else if (s > 0) {p->data[i - s] = p->data[i];}}n -= s;printf("\n删除后的表长为:%d",n);printf("\n删除后的线性表为: ");for (i = 0; i < n; i++) {printf("%c ",p->data[i]);}printf("\n");}void delect2(sqlist *p) {int n;n = p->n;int i,j,s;char c;s = 0;if (n == 0) {printf("下溢\n");return;}for (i = 0,j=n; i < j; i++) {if (p->data[i] >= 48 && p->data[i] <= 57) {for (j = n; j > i; j--,n--) {if (p->data[j] < 48 && p->data[j] >57) {c = p->data[i];p->data[j] = p->data[i];p->data[j] = c;s++;break;}}}}n -= s;printf("\n删除后的表长为:%d", n);printf("\n删除后的线性表为: ");for (i = 0; i < n; i++) {printf("%c ", p->data[i]);}}void main() {int i;sqlist Sqlist;init(&Sqlist);printf("方法一(一步到位):\n");delect1(&Sqlist);printf("方法二(交替扫描):\n");delect2(&Sqlist);gets();}
矩阵相乘:
#include<stdio.h>
void main() {
int b[3][2] = { {1,2},{3,4},{5,6 } };
int a[2][3] = { {1,2,3},{4,5,6} };
int c[2][2];
int i = 0, j = 0, k = 0;
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
c[i][j] = 0;
for (k = 0; k < 3; k++) {
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
}
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
printf("%d\n", c[i][j]);
}
}
}
- 数据结构与算法 -- 算法
- 【数据结构与算法】浅谈数据结构与算法
- 【数据结构与算法】【Some】数据结构与算法
- 数据结构笔记-----数据结构与算法
- 【数据结构与算法】数据结构备忘
- 数据结构与算法总论
- 数据结构与算法总论
- 数据结构与算法基础
- 数据结构与算法总论
- 数据结构与算法
- 数据结构与算法基础
- 数据结构与算法笔记
- 数据结构与算法
- 数据结构与算法
- 数据结构与算法
- 算法与数据结构简介
- 数据结构与算法
- 数据结构与算法(1)
- deferred对象详细解读
- cookie和session的联系和区别
- LeetCode--Permutation Sequence
- React Native
- C# 单例设计模式
- 数据结构与算法
- 51Nod 1298 圆与三角形
- Java中理解IO工作原理示意图
- 【Java】虚拟机执行引擎
- 盲评的办法
- WOJ1296-Coins
- 异步消息处理机制
- JAVA 1 笔记
- 【JMeter 菜鸟实操之五】ant+jenkins 完善html结果报告