随笔分类 - 数据结构和算法
摘要:基本思想: 在待排记录中依次选择关键字最小的记录作为有序序列的最后一条记录,逐渐缩小范围,直至全部记录选择完毕。 排序过程: ①首先扫描整个待排列序列,通过 n-1 次比较,找到关键词值最小的结点,将它与第一个记录交换 ②再通过 n-2 次比较,从剩余的 n-1 次记录中找出关键字次小的记录,将它与
阅读全文
摘要:1.把n个待排序的元素看成为一个有序表和一个无序表; 2.开始时有序表中只包含一个元素,无序表中包含有n - 1个元素; 3.排序过程中每次从无序表中取出第一个元素,把它的排序码依次与有序表元素的排序码进行比较,将它插入到有序表中的适当位置,使之成为新的有序表。 1 #include<stdio.h
阅读全文
摘要:1,非递归方式: 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int BinarySearch(int arr[], int arrlen, int targetVal) { 5 //int arrlen = sizeof(arr) / sizeof(a
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> //用二叉链表存储方式建树(完全二叉树) typedef struct BitTree { int data; struct BitTree* LChild; //左子树 struct BitTree* RChild; //右
阅读全文
摘要:1,将1-9入队列 2,出队列 3,进栈 4,出栈 #include<stdio.h> #include<stdlib.h> #include "stack.h"; #define Capacity 9 typedef struct Node { int data; struct Node* nex
阅读全文
摘要://获取二叉树叶子节点个数 #include<stdio.h> #include<stdlib.h> //用二叉链表存储方式建树(完全二叉树) typedef struct BitTree { int data; struct BitTree* LChild; //左子树 struct BitTre
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> //用二叉链表存储方式建树(完全二叉树) typedef struct BitTree { int data; struct BitTree* LChild; //左子树 struct BitTree* RChild; //右
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> //用二叉链表存储方式建树(完全二叉树) typedef struct BitTree { int data; struct BitTree* LChild; //左子树 struct BitTree* RChild; //右
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> //用二叉链表存储方式建树(完全二叉树) typedef struct BitTree { int data; struct BitTree* LChild; //左子树 struct BitTree* RChild; //右
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> //二叉链表 //typedef struct BitLink { // int data; // struct BitLink* leftChild; //左指针 // struct BitLink* rightChild;
阅读全文
摘要://键盘输入若干个整数,按输入数据逆序建立一个带头结点的单链表(头插入创建单链表) #include<stdio.h> #include<stdlib.h> typedef struct Link { int data; struct Link* next; }link; //头插入的方式初始化链表
阅读全文
摘要:有一个不带头结点的单链表L(至少有1个结点),第一个结点指针为head,编写算法将L逆置,即最后一个结点变成第一个结点,倒数第二个结点变成第二个结点,如此等等。 #include<stdio.h> #include<stdlib.h> //链表中节点的结构 typedef struct Link {
阅读全文
摘要:1,定义链队列结点结构,链队列结构,初始化空链队列 #include<stdio.h> #include<stdlib.h> //定义链队列结点结构 typedef struct LinkQueueNode { int data; struct LinkQueueNode* next; }LQNod
阅读全文
摘要://循环队列 #include<stdio.h> #include<stdlib.h> #define Capacity 6 typedef struct Queue { int data[Capacity]; int front; //队头指针 int rear; //队尾指针 }queue; q
阅读全文
摘要:1,定义队列,并初始化队列(赋予一个队列10个元素,元素赋值为 -1 ) //顺序队列,定义队列并初始化队列,将队列中的元素初始化为-1 #include<stdio.h> #include<stdlib.h> #define Capacity 10 typedef struct Queue { i
阅读全文
摘要:1,定义一个链栈,并压入一个元素 1 //定义一个链栈,并压入一个元素 2 3 /* 4 #include<stdio.h> 5 #include<stdlib.h> 6 7 //定义链栈结点结构 8 typedef struct LinkStackNode { 9 int data; 10 str
阅读全文
摘要:1,创建一个空栈,并向栈中压入1个元素 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 #define CAPACITY 100 //栈的容量 5 #define SIZE 10 //如果栈需要扩充,每次扩充10 6 7 //定义栈 8 typedef st
阅读全文
摘要:1,创建一个双向链表,并初始化赋值 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 typedef struct Link { 5 int data; 6 struct Link* prior; 7 struct Link* next; 8 }link;
阅读全文
摘要:1,循环链表的初始化 定义一个头结点和尾指针的方式,头结点在这里是用来连接 第一个结点和最后一个结点的结点 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 typedef struct Link { 5 int data; 6 struct node* ne
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> //链表中节点的结构 typedef struct Link { int data; struct Link* next; }link; //链表初始化 link* initLink(link* head_node) { he
阅读全文

浙公网安备 33010602011771号