ICode9

精准搜索请尝试: 精确搜索
  • 堆排序2020-01-25 17:44:32

    采用数组存储二叉堆结构,数组下标从1开始,对于第i个结点,2i是其左孩子,2i+1是其右孩子。设结点总个数为n,若2i > n,则结点i没有左孩子;若2i+1 > n,则结点i没有右孩子。 堆排序最重要的是一步是筛选操作,即调用heapAdjust()函数。建立一个堆,是从最后一个非叶子结点(其下标为n / 2向下

  • 顺序表的创建—数据结构算法2020-01-19 19:04:36

    代码功能截图: 部分源码: #include<stdio.h>#include<stdlib.h>#define MAXSIZE 20typedef int ElemType;typedef struct{ ElemType a[MAXSIZE]; int length;}SqList;SqList a,b,c;void creat_list(SqList *l);void out_list(SqList l);void insert_sq(SqList *l,int i,E

  • 排序-拆半插入排序2019-12-19 20:57:30

    二分插入排序 找元素的时候采用二分查找来提高效率 #include <iostream> using namespace std; #define MAXSIZE 20 //顺序表的最大长度 typedef struct { int key; char *otherinfo; }ElemType; //顺序表的存储结构 typed

  • c语言实现顺序表的基本操作2019-10-13 11:58:05

    转自 https://www.cnblogs.com/rookiefly/p/3425075.html 原作者:Step by Step     经过三天的时间终于把顺序表的操作实现搞定了。(主要是在测试部分停留了太长时间) 1;线性表顺序存储的概念:指的是在内存中用一段地址连续的存储单元依次存储线性表中的元素。 2;采用的实现方式:一

  • 顺序表习题(1)-打印非递减数组a与b的升序并集(去除重复元素)2019-10-09 23:58:14

    1 void Print_Union(SqList a,SqList b) 2 { 3 int p = 0, q = 0; //初始化指针 4 int flag = -1; //记录上一次打印的元素 5 while (p!=a.length&&q!=b.length) 6 { 7 //a与b均非空时 8 if (a.data[p] > b.data[q]) 9 {10

  • 顺序表SqList(动态)2019-09-25 10:04:22

    动态顺序表SqList,严蔚敏《数据结构》第二章-顺序表-配套代码,完整如下 (已调试通过): #ifndef SEQUENCELIST_H #define SEQUENCELIST_H #include <stdio.h> #include <stdlib.h> //提供malloc、realloc、free、exit原型 /* 宏定义 */ #define TRUE 1 //真 #define FAL

  • 简单选择排序2019-09-22 09:41:30

    每一趟在n-i+1(i=1,2,…,n-1)个记录中选取最小的记录作为有序序列的第i个记录。 时间复杂度O(n2) #include <iostream> #include <cstdlib> //顺序表结构 #define MAXSIZE 10 //要排序数组个数最大值 typedef struct { int r[MAXSIZE + 1]; //存储要排序数组,r[0]作为哨兵

  • 冒泡排序(BubbleSort)2019-09-22 09:41:09

    两两比较相邻记录,如果反序则交换,直到没有反序的记录。 时间复杂度O(n2) #include <iostream> #include <cstdlib> //顺序表结构 #define MAXSIZE 10 //要排序数组个数最大值 typedef struct { int r[MAXSIZE + 1]; //存储要排序数组,r[0]作为哨兵或临时变量 int length;

  • 数据结构:有序顺序表里插入一个数,使得顺序表依然有序。2019-09-15 18:38:06

    废话不多说,直接上程序 #include <stdio.h> #include #define MaxSize 20 typedef int ElemType; typedef struct { int length; ElemType data[MaxSize+1]; }SqList; //为了方便,顺序表的第一个位置不放值,也就是下标为0的 void CreateList(SqList *&L,ElemType a[],int

  • 2.27√ 2.25的条件下作两点修改:表AB可能存在值相同的元素,但新生成的表C的元素值各不相同;利用A表空间存放表C2019-09-15 15:07:48

    #include<stdio.h> #include<malloc.h> #include <stdlib.h> #define maxsize 10 typedef int ElemType; typedef int status; typedef struct { ElemType *data; int length; }SqList; void creat(SqList *L) { int len; printf(&qu

  • 顺序存储的线性表的基本操作2019-09-14 16:55:29

    刚开始学数据结构,几乎算是什么都不会,想记录一下学习的东西,所以就学别人开始写博客。     刚学了顺序存储的线性表的基本操作,把操作写了一遍。可能会有错误。   顺序存储的线性表,用结构体类型。注意:结构体并不是用来存储元素的,elem才是存储元素的首地址 1 typedef struct2 {3

  • 数据结构实验(C语言):数组2019-08-30 17:01:23

    文章参考过网上的内容,如果侵权,请联系 #include<stdio.h> #include<stdlib.h> #include<malloc.h> #define LISTSIZE 20 #define LISTINCREASE 10 typedef struct{ int *elem; int length; int listsize; } Sqlist;//表结构 void InitList(Sqlist &L)//建立表 { L.ele

  • 数据结构——长度为n的顺序表L,编写一个时间复杂度为O(n),空间复杂度为O(1)的算法,该算法删除线性表中所有值为x的数据元素2019-08-17 16:04:58

    题目:长度为n的顺序表L,编写一个时间复杂度为O(n),空间复杂度为O(1)的算法,该算法删除线性表中所有值为x的数据元素。 思想: 记录等于X的值的个数i,遇到不是X的位置就把值放到前面i个位置上 代码展示: #include<stdio.h> #include<stdlib.h> #define ElemType int #define InitSiz

  • 设计一个算法将一个顺序表逆置2019-08-15 18:00:10

    #include<iostream>#include<malloc.h>using namespace std;typedef struct { int length;//保存长度 int data[40];//数组} SqList;/*算法1:设计一个高效的算法,将顺序表中的所有元素逆置、要求算法空间股咋度为o(1)*///初始化顺序表void initReverse(SqList &s,int *a,int l){

  • 数据结构-顺序表基本操作的实现(含全部代码)【转】2019-07-27 09:04:21

    数据结构-顺序表基本操作的实现(含全部代码)   今天起开始编写数据结构中的各种数据结构及其算法的实现。 主要依据严蔚敏版数据结构教材以及王道数据结构考研辅导书。 今天是线性表中的顺序表的实现,主要实现函数如下,读者有需要可以评论,我可以适当加几个。     CreatList

  • 简单的c语言数据结构的 合并两个表的数据;2019-07-20 14:40:09

    #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 100 #define M 100 #define N1 200 #define Sqlist struct lists #define Sqlist1 struct list #define Sqlists struct list_sus //定义一个结构体 struct lists{

  • 顺序表插入、删除算法用C语言来实现2019-06-14 23:06:01

    #include<stdio.h> #include<stdlib.h> //-------- 线性表的动态分配顺序存储结构 ----------- int LIST_INIT_SIZE=100;   //顺序表存储空间初始尺寸 int LISTINCREMENT=10;  //顺序表存储空间分配增量 typedef  int  ElemType;          //顺序表元素的数据类型为

  • 指针与指针内存储地址的关系2019-06-12 14:42:18

    1 #pragma region 指针++,指针内存储的地址增加m位,m根据存储内容的所占字节数的大小决定 2 3 //这里通过一个顺序表来说明这一关系 4 using namespace std; 5 typedef int Status; 6 typedef int ElemType; 7 constexpr auto MAXSIZE = 100;// 最大长度; 8 typedef struct SqList

  • 数据结构之线性表12019-06-01 19:39:28

    hello 大家好,今天是兴趣祖入住博客之后的第一次写博。兴趣祖想通过写博的方式记录自己萌新成长的经验。我遇到的问题也很大可能是萌新们遇到的问题,我会把我自己的理解和问题反馈给大家,希望对萌新有所帮助,欢迎批评与指正,谢谢!   1.线性表的顺序存储结构 (线性表的定义啥的都在书上,我

  • 线性表的顺序存储结构——顺序表2019-05-20 20:52:57

    一.基本运算的实现 1.建立顺序表 void CreateList(SqList * & L,ElemType a[],int n) //由a中的n个元素建立顺序表{ int i = 0,k = 0; //k表示L中的元素个数,初始值为0 L = (SqList *)malloc(sizeof(SqList)); //分配线性表的空间 while(i < n) { L->data[k] =

  • 线性表的基本操作2019-05-19 15:49:27

    实现线性表的增加删除定位等功能。(编译执行环境vc6.0,因为目标院校上机考是用这个版本的) #include<stdio.h>#include<malloc.h>#define Maxsize 100typedef struct{ int array[Maxsize]; int length;}SQlist;int findElem(SQlist L,int x){ int i=0; for(i; i<L.length

  • 堆排序和简单选择排序2019-05-06 11:50:33

    简单选择排序就是每次从i到N-1中选择最小的数,然后放在第i个位置,其算法复杂度为O(N2); 堆排序是简单选择排序的改进,通过建立最大堆,每次将最大堆的根节点取出放在最后的位置,然后再重新调整为最大堆,时间复杂度为O(NlogN)。 简单排序算法 void Select_Sort(SqList *L) /*简单选择

  • 线性表的实现2019-04-17 16:53:05

      1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #define N 64 //宏定义 5 typedef int datatype; 6 //线性表的结构体定义,连续存储空间,last用于表明最后一个数据元素的存储元素 7 typedef struct list 8 { 9 //线性表是一个连续存储空间,用数

  • 希尔排序(缩小增量排序)2019-03-31 11:37:58

    1 #include<stdio.h> 2 #include<stdlib.h> 3 4 typedef struct 5 { 6 int *data; 7 int length; 8 }Sqlist; 9 10 11 /*顺序表的初始化*/12 void InitList(Sqlist &L, int l)13 {14 L.data = (int*)malloc((l+1)*sizeof(int));15 L.length = 0;16

  • 顺序表算法实现2019-03-28 13:55:45

    初始化顺序表 void InitList(SqList * &L) { L = (SqList *)malloc(sizeof(SqList)); if (!L) { exit(OVERFLOW); } L->length = 0; } 销毁顺序表 void Destroy(SqList * &L) { free(L); } 判断顺序表是否为空 Status ListEmpty(SqList * &L) { if (L->length == 0

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有