
数据结构
文章平均质量分 57
云胡同学
GitHub 地址:https://github.com/stevenling
微信公众号:yunhu_123
展开
-
c++ 单链表的定义与使用
#include<iostream>using namespace std;typedef struct node * LinkList;typedef struct node{ int data; LinkList next;}Node;//Node 代表 struct node Linklist 代表 struct node *LinkList creat()//创建原创 2016-06-23 19:04:40 · 2755 阅读 · 0 评论 -
数据结构之冒泡排序
思路外循环和之前一样,每相邻两个数都比较,最小的就沉在最右边,内循环的范围一次一次减少。代码,因为一个一个沉下去的就是排好的,相邻元素顺序错误我们就交换。过程代码#include<stdio.h>int main(){ int a[100], i, n, j, temp, max, k;//n为需要排序的数的数量 scanf("%d",&...原创 2019-01-27 18:09:31 · 288 阅读 · 0 评论 -
蛇形填数
#include<stdio.h>#include<string.h>int main(){ int a[10][10], n,tot= 0, x, y; memset(a, 0, sizeof(a));//刚开始将数组元素全部清零 tot = a[x=0][y=0] = 1; scanf("%d", &n);...原创 2016-04-16 14:07:40 · 232 阅读 · 0 评论 -
模拟链表
#include<stdio.h>#include <stdlib.h>int main(){ int data[101], right[101];//right[i] = n代表data[i]右边的元素是data[n] eg right[3] = 10 表示data[3]右边的元素是data[10] int i, n, t, len; sc...原创 2016-04-18 22:14:08 · 286 阅读 · 0 评论 -
数据结构之堆排序
//构造一个最大堆,然后反着输出去#include<stdio.h>int h[101];int n;void swap(int x, int y){ int t; t = h[x]; h[x] = h[y]; h[y] = t;}void siftdown(int i)//需要向下调整的编号 需要的是最大堆 父节点小于子节点都要调整{...原创 2016-04-23 17:10:54 · 287 阅读 · 0 评论 -
数据结构之比较排序
思路比较法的一个简单思路是一组数据要弄两层循环,比较的那个数从第1个到n-1个(n为比较的数的数量),被比较的数从第2个到n个。假设我们需要的排序是从大到小(从小到大相同的道理),两个数比较,如果被比较的数也就是后面的数比前面大,那我们就把这两个数拿来交换。这里详细说一下交换的思路,假设有两杯水,一杯是开水,编号为a,一杯是可乐,编号为b,我们可以取一个空水杯,首先将编号a开水倒入空水杯c...原创 2019-01-24 13:50:50 · 251 阅读 · 0 评论 -
数据结构之冒泡排序
外循环和之前一样,每相邻两个数都比较,最小的就沉在最右边,内循环的范围一次一次减少。 代码,因为一个一个沉下去的就是排好的,相邻元素顺序错误我们就交换。#include<stdio.h>int main(){ int a[100], i, n, j, temp, max, k;//n为需要排序的数的数量 scanf("%d",&n); for(i=0;i<n原创 2017-07-22 23:38:47 · 290 阅读 · 0 评论 -
数据结构之直接插入排序
思路将待排序的数分为两部分,一部分是已排序,另一部分是未排序。将未排序的数一个一个和已排序的数比较,插入到合适的位置。过程代码#include<iostream>using namespace std;void insertSort(int a[]){ int i, temp, j, len; len = 6; for(j = 1; j < len; j+...原创 2019-01-24 13:17:31 · 483 阅读 · 0 评论 -
二叉树的建立及遍历
#include<iostream> using namespace std; typedef struct node { struct node *lchild; struct node *rchild; char data; }BiTreeNode, *BiTree; BiTree T;void createBiTree(BiTree &T原创 2017-05-25 21:11:49 · 211 阅读 · 0 评论 -
二叉排序树基本用法
#include <stdio.h>#include <stdlib.h>#define max 50typedef struct liuyu{ int data; struct liuyu *lchild,*rchild;}test;liuyu *root,*p,*q[max];int sum=0;int m=sizeof(test); int count = 0原创 2017-05-25 20:07:39 · 259 阅读 · 0 评论 -
通过栈实现括号匹配
首先输入一个待匹配的括号序列,如果是左括号将其压入栈中,如果是右括号则与当前栈顶的括号相匹配(左中括号匹配右中括号,左小括号匹配右小括号),若匹配失败,输出匹配失败,程序结束,若匹配成功,将栈顶括号出栈,直到最后一个括号匹配完成。 若最后栈为空输出匹配成功,不为空输出匹配失败。#include <iostream>#include <string>#define MaxSize 100usi原创 2017-05-04 21:53:31 · 379 阅读 · 0 评论 -
单链表基本操作
#include<iostream>#include"stdlib.h"using namespace std;typedef struct node //定义结点{ int data; //结点的数据域为整型 struct node *next; //结点的指针域}ListNode;int dataflag = 0;i原创 2017-04-17 16:50:39 · 438 阅读 · 0 评论 -
算法题之数组左移
题目理解: a数组中有10个数,a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 假设左移4个数,那么结果为{5, 6, 7, 8, 9, 10, 1, 2, 3, 4}。思路1: 如果左移p个数,将前p个数存到临时数组中,然后p之后的所有数据向前移动p个数,最后将临时数组中原来的前p个数添加到数组的末尾。b[0] - b[p-1] = a[0] - a[p-1...原创 2017-03-28 19:45:23 · 3131 阅读 · 0 评论 -
线性表基本操作
#include#include#define LIST_INIT_SIZE 10 //初始分配量#define LISTINCREMENT 5 //分配增量typedef int ElemType;typedef struct{ ElemType *elem;//存储空间基址 int length; //当前长度原创 2017-03-17 18:00:08 · 422 阅读 · 1 评论 -
顺序表排重
#include<stdio.h>#include<stdlib.h>#define LIST_INIT_SIZE 10 //初始分配量#define LISTINCREMENT 5 //分配增量typedef int ElemType;typedef struct{ ElemType *elem;//存储空间基址 int length; //当前长度原创 2017-03-17 17:59:04 · 523 阅读 · 0 评论 -
单链表逆序
#include<stdio.h>struct node{ int data;//链表的数据 struct node *next;//结构体指针指向下一个数据};int main(){ struct node *p, *q, *head, *t, *newp, *newhead;//p是临时指针 表示当前节点 int n, i, a, len = 0;原创 2017-02-22 22:23:03 · 240 阅读 · 0 评论 -
线性表的顺序存储
用结构体实现 结构体数据成员为数组 和 一个整型的length 指最后一项的位置#define Maxlength 100struct sequencelist{ int data[Maxlength]; int length;};删除 void delete1(struct sequencelist *list, int index){ //刚构造时data[原创 2016-06-21 21:29:45 · 263 阅读 · 0 评论 -
数据结构之选择排序
思路将待排序的数分为两部分,一部分是已排序,另一部分是未排序。将未排序部分中最小的数放在已排序部分后。过程代码#include<iostream>using namespace std;void selectSort(int a[], int len){ int smallestIndex; int i, j, temp; for(i = 0; i < l...原创 2019-01-27 18:17:44 · 1425 阅读 · 0 评论