链表大小排序方法c语言,5 种排序算法--C语言链表

源码地址 GitHub:https://github.com/GYT0313/C-DataStructure/blob/master/sortIn5.c

包括:

冒泡排序

快速排序

选择排序

插入排序

希尔排序

运行:

注意:快速排序的核心代码应该没有问题,但是不知道为什么链表长度的值MAX会跑到链表中,找了半天没找出来!!!

7d0c5355cc0c662a88a70c993b60425c.gif

代码:

#include

#include

#define MAX 8 /*线性表的最大长度*/

typedef int ElemType; /*数据元素类型*/

/*顺序表类型定义*/

typedef struct

{

ElemType data[MAX];

int length; /*当前表的长度*/

} SeqList;

/* 初始化 */

SeqList *InitSeqlist()

{

SeqList *L;

L = (SeqList *)malloc(sizeof(SeqList));

L->length = 0;

return L;

}

/* 输入 */

void input(SeqList *L)

{

int i;

srand( time(NULL) );

for ( i=0; i

{

L->data[i] = rand()%100;

L->length++;

}

}

/* 输出 */

void output(SeqList *L)

{

int i;

for ( i=0; i

printf("%-4d", L->data[i]);

printf("\n\n");

}

/* 冒泡排序 O(n^2) */

void BubbleSort( SeqList *L )

{

int i, j, flag, tmp;

for ( i=1; ilength; i++ ) /* 循环N-1次 */

{

flag = 0; /* 标志位 */

for ( j=0; jlength-i; j++ )

{

if ( L->data[j] > L->data[j+1] )

{

flag = 1;

tmp = L->data[j];

L->data[j] = L->data[j+1];

L->data[j+1] = tmp;

}

}

if ( flag == 0 )

return ;

}

}

/* 快速排序 O(nlog2^n) */

void QuickSort( SeqList *L, int s, int t )

{

output(L);

int i, j, tmp;

i = s;

j = t;

if (s >= t)

{

return 0;

}

tmp = L->data[s];

while ( i < j )

{

/* 右分区向左扫描 */

while ( idata[j] > tmp ) /* 右分区a[j] >= tmp ,继续向左扫描 */

j--;

if ( i

{

// 交换

int t = L->data[j];

L->data[j] = L->data[i];

L->data[i] = t;

i++;

}

/* 左分区向右扫描 */

while ( idata[i] < tmp )

i++;

if ( i

{

int t = L->data[j];

L->data[j] = L->data[i];

L->data[i] = t;

j--;

}

}

L->data[i] = tmp;

/* 递归调用 */

QuickSort( L, s, i-1 );

QuickSort( L, i+1, t );

}

/* 选择排序 O(n ^2) */

void selectSort( SeqList *L )

{

int i, j, min, tmp; /* 该次循环最小值下标 */

for ( i=0; ilength-1; i++ )

{

for ( j=i+1, min=i; jlength; j++ )

{

/* 若最小值为a[min] 则重新赋值min */

if ( L->data[j] < L->data[min] )

min = j;

}

/* 判断 a[i] 是否是最小值,若不是则重新赋值 */

if ( min != i )

{

tmp = L->data[i];

L->data[i] = L->data[min];

L->data[min] = tmp;

}

}

}

/* 插入排序 O(n^2) */

void InsertSort( SeqList *L )

{

int i, j, tmp;

/* i =1, 第一个数据作为有序对,其余数据作为无序对 */

for ( i=1; ilength; i++ )

{

tmp = L->data[i]; /* tmp 为待排数据 */

j = i-1; /* j指向待排数据的前一个数据 */

/* 循环找出待排数据的位置,同时又有数据的后移 */

while ( j>=0 && tmp < L->data[j] )

{

L->data[j+1] = L->data[j];

j--;

}

L->data[j+1] = tmp; /* j+1 为带插入数据的位置 */

}

}

/* 希尔排序 O(n^(2/3) */

void ShellSort( SeqList *L )

{

int d, i, j, tmp;

/* 每次以 d 为间距进行分组 */

for ( d=L->length/2; d>0; d/=2 )

{

/* 每次进行每组的一个数据的排序(分时) */

for ( i=d; ilength; i++ )

{

tmp = L->data[i];

/* 直接排序,从后往前 */

for ( j=i-d; j>=0 && tmpdata[j]; j-=d )

{

L->data[j+d] = L->data[j];

}

L->data[j+d] = tmp; /* 因为上层for循环跳出多执行了一次 j-d */

}

}

}

/* 菜单 */

int menu()

{

int choice;

printf(" |****************顺序表排序操作************|\n");

printf(" | 1. 冒泡排序法 |\n");

printf(" | 2. 快速排序法 |\n");

printf(" | 3. 选择排序法 |\n");

printf(" | 4. 插入排序法 |\n");

printf(" | 5. 希尔排序 |\n");

printf(" | 0. 退出 |\n");

printf(" |******************************************|\n");

do{

printf("请输入(0~5): ");

scanf("%d", &choice);

}while( choice < 0 || choice > 5 );

return choice;

}

void form()

{

SeqList *L;

int flag=1;

while ( flag )

{

switch( menu() )

{

case 1: /* 1. 冒泡排序法 */

printf("\t\t冒泡排序:\n");

L = InitSeqlist();

input( L );

printf("\n\tBefore sort: \n");

output( L );

BubbleSort( L );

printf("\tSort:\n");

output( L );

printf("\n");

system("pause"); //暂停

system("cls"); //清屏

break;

case 2: /* 2. 快速排序法 */

printf("\t\t快速排序:\n");

L = InitSeqlist();

input( L );

printf("\n\tBefore sort: \n");

output( L );

QuickSort( L, 0, MAX );

printf("\tSort:\n");

output( L );

printf("\n");

system("pause"); //暂停

system("cls"); //清屏

break;

case 3: /* 3. 选择排序法 */

printf("\t\t选择排序:\n");

L = InitSeqlist();

input( L );

printf("\n\tBefore sort: \n");

output( L );

selectSort( L );

printf("\tSort:\n");

output( L );

printf("\n");

system("pause"); //暂停

system("cls"); //清屏

break;

case 4: /* 4. 插入排序法 */

printf("\t\t插入排序:\n");

L = InitSeqlist();

input( L );

printf("\n\tBefore sort: \n");

output( L );

InsertSort( L );

printf("\tSort:\n");

output( L );

printf("\n");

system("pause"); //暂停

system("cls"); //清屏

break;

case 5: /* 5. 希尔排序 */

printf("\t\t希尔排序:\n");

L = InitSeqlist();

input( L );

printf("\n\tBefore sort: \n");

output( L );

ShellSort( L );

printf("\tSort:\n");

output( L );

printf("\n");

system("pause"); //暂停

system("cls"); //清屏

break;

case 0: /* 0. 退出 */

flag = 0;

}

}

}

int main()

{

form();

return 0;

}

C/C++ 链表的选择排序算法详解及源码 链表的选择排序算法是通过比较链表中的节点值,选出当前最小的节点,然后将该节点从链表中删除,并将其插入到已排序部分的末尾。重复这个过程,直到整个链表排序完成。 阅读详情

相关推荐

算法策略 | MACD跨周期短线交易策略开发(股指+商品双版)

量化策略开发,高质量社群,交易思路分享等相关内容

松鼠宽客的博客 2549

链表大小排序方法c语言,链表排序——选择排序法(纯C语言版)

因此,对于链表来说,二分法检索是不可以的(对顺序链表或排序后的链表是可以用的)。% 查找和排序旋转数组的最小数字5815.06% 递归和循环斐波那契数列9323.32% 位运算二进制中1的个数7438.22% 代码的完整性数值的整数次方4920.55% 代码的完整性调整数组顺序使奇数位于偶数前面4223.23% 代码的鲁棒性链表中倒数第k个结点4423.98% 代码的鲁棒性反转链表5626.05%...

weixin_36272668的博客 2072

基于eBPF和LSM的强制文件访问控制系统架构设计和实现

本文介绍了一种基于 eBPF 与 Linux 安全模块(LSM)实现的强制文件访问控制系统。该系统利用 eBPF 的高性能和动态加载能力以及 LSM 的系统调用拦截功能,提供了灵活且强大的文件访问控制策略。文章详细描述了系统的设计思路、架构组成、关键代码实现及错误处理方式。通过用户空间程序与内核态 eBPF 程序的协作,实现了对文件操作的实时监控和控制,支持动态更新安全策略而无需重启系统。此外,文中还讨论了未来可能的扩展方向,如增加更多 hook 点、集成其他安全模块以及性能优化等。

Linux内核研究者 1872

C语言链表排序

#include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> struct student { char num[10]; char name[10]; int age; char sex[5]; char tel[15]; char addr[50]; struct student *next;//指针域 }; struct student* creat

qq_44574863的博客 502

C#串口通讯实战:如何用SerialPort类搞定工业传感器数据采集(附完整代码)

本文详细介绍了如何使用C#的SerialPort类实现工业级传感器数据采集,涵盖串口通讯基础配置、数据帧处理、异常恢复机制及性能优化策略。通过实战代码示例,帮助开发者构建稳定可靠的工业数据采集系统,特别适合需要处理高频数据采集和复杂工业环境的场景。

weixin_42525551的博客 1096

C-Free使用教程(使用C-Free编写C语言程序)

C-Free使用教程(使用C-Free编写C语言程序) 安装C-Free 5.0 C-Free 是一款国产的Windows下的C/C++ IDE,最新版本是 5.0,整个软件才 14M,非常轻巧,安装简单。 下载地址:C-Free 5.0下载 按照教程中的说明安装并 C-Free 5.0。 需要注意的是:C-Free 5.0 在 XP、Win7 下能够完美运行,在 Win8、Win10 下可能会存在兼容性问题,读者可以先尝试安装,不行的话再使用 VS、Dev C++、Code::Blocks 等代替。 运行

ccc369639963的博客 1万+

链表排序——选择排序法(纯C语言版)

链表选择排序/********************************* 链表的排序 *******************************************/ /* ========================== 功能:选择排序(由小到大) 返回:指向链表表头的指针 ========================== 选择排序的基本思想就是反复从还

xufan0001的博客 4450

C# WinForm实战:用正运动ECI2418/2618卡实现4轴连续插补(附完整源码)

本文详细介绍了如何使用C# WinForm结合正运动ECI2418/2618运动控制卡实现4轴连续插补功能。从环境配置、核心架构设计到连续插补实现,提供了完整的开发流程和源码示例,帮助开发者快速掌握工业自动化领域的运动控制技术。

weixin_28454475的博客 155

C语言单链表按数字大小排序,C语言单链表的3种排序算法,插入排序,冒泡排序,选择排序...

//插入排序stu *view_sort_math(stu *head){struct student *first;struct student *t;struct student *p;struct student *q;first = head->next;head->next = NULL;while (first != NULL){for (t = first, q = he...

weixin_30546201的博客 809

蓝牙开发实战:如何用Wireshark抓取HCI协议包(附完整分析步骤)

本文详细介绍了如何使用Wireshark抓取和分析蓝牙HCI协议包,包括环境搭建、过滤器配置技巧、数据包深度解析及高级调试方法。通过实战案例,帮助开发者快速定位蓝牙连接问题,提升调试效率。

cuda7parallel的博客 1161

解锁PyCharm+Deepseek:本地部署AI编程超能力

在本次探索中,我们成功地在 PyCharm 中实现了 DeepSeek 的本地化部署,这一过程虽然涉及多个步骤,但每一步都为我们开启 AI 编程大门奠定了基础。从安装最新版 PyCharm,确保我们拥有一个功能强大且兼容性良好的开发环境,到注册 DeepSeek 账号并获取 API Key,这是连接我们与强大 AI 能力的关键纽带。接着,在 PyCharm 中安装 Continue 插件并进行精细配置,让 DeepSeek 能够深度融入我们的编程流程。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 5556

数据结构(C语言)单链表的几个算法

上篇写道了创建单链表和遍历单链表的实现 现在写几个常见的算法实现; 主函数代码: #include <stdio.h> #include <malloc.h> #include <stdlib.h> typedef struct Node{ int data; struct Node * pNext; }NODE,* PNODE; PNODE create_list(void); void traverse_list(PNODE pHead); int..

m0_63137469的博客 1550

【人工智能之深度学习】15. 工业时序预测实战:LSTM与TCN融合的装备故障预警系统设计与实现

摘要:工业装备故障预警是智能制造领域的核心技术之一,其通过分析传感器时序数据实现故障提前预测,可显著降低运维成本并提升设备可靠性。本文针对工业时序数据多源异构、非平稳性、噪声干扰及样本不平衡等挑战,提出一种LSTM与TCN融合的故障预警架构——利用TCN捕捉局部时序特征,结合注意力增强LSTM建模长期依赖关系,通过门控机制实现特征自适应融合。以3MW风电齿轮箱为研究对象,设计包含数据预处理、特征工程、模型训练及部署的完整流程,实验结果表明,该融合模型准确率达94.6%,故障预测提前量较单一模型提升30%以上

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1460

嵌入式学习笔记——C语言基础笔记(超直观详细!!包含数据结构,排序算法介绍与动图)

简要涵盖嵌入式C语言指针,链表,排序算法介绍,有动图超详细

Mr_Kaws的博客 5070

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

十大排序之桶排序(C语言实现)

基础十大排序(7)———桶排序(c语言版本) 桶排序(Bucket sort) 桶排序 (Bucket sort)或所谓的箱排序,是一个排序算法,工作的原理是将数组分到有限数量的桶子里。每个桶子再个别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序)。桶排序是鸽巢排序的一种归纳结果。当要被排序的数组内的数值是均匀分配的时候,桶排序使用线性时间(Θ(n))。但桶排序并不是 比较排序...

weixin_45762587的博客 5862

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

C语言:再也不写排序算法

在C语言一个小项目里面,大多数情况我们都是选择自己造车轮,比如需要自己写一个排序算法或者链表,这样的过程在学习的时候动手是充满意义的,但是到了大项目之中,用标准库和别人封装好的算法不香吗?倘若盖一栋楼之前,连每一个砖块都需要我们挖土烧砖,那么这是多么可怕巨大的工程量。

Bamboo 1万+

大一上C语言错题集

就没办法

a1391011582的博客 8061

c语言常用函数comb,基础排序算法

简单排序插入排序想象一下插队的过程...一个人通过插队的方式排到前面,而将原本在他前面的人挤到了后面的位置。对数排序时也是这样,为了从小到大排序,需要将一个数放到前面,而将那些比它大的数挤到了后面,从而实现了排序的目的。排序过程当一个数列A开始进行排序时就已经被划分成了两个部分--有序的和无序的,由于只有一个数的数列可以被看作已经有序,所以将数列A中的第一个元素看作有序的部分(图中6),后面的其他...

weixin_34648437的博客 2052

【C语言】数据结构——排序(一)

今天我们来学习排序,包括直接插入排序,希尔排序,选择排序,堆排序,冒泡排序,快排以及归并排序。 冒泡排序,快排和归并排序我们放在之后分析,今天主要来分析前面的。

qq_64818885的博客 1483

无头结点的单链表直接插入排序

1、问题描述 插入排序是把一个记录插入到已排的有序序列中,使得这个序列在插入该记录后仍然保持有序。插入排序中较为简单较为简单的一种就是直接插入排序,其插入的位置的确定方法是将待插入的记录与有序区中的各记录自右向左依次比较其关建字值的大小,本实例要求使用直接插入排序由小到大进行排序。 2、程序代码 3、输出结果 ...

xiaochenxiaoren的博客 2767

学懂C语言(四十):C语言 数据结构与算法详解

C语言 数据结构与算法详解

编程技术探索者,分享C/C++、C#、Java、数据库等开发经验,聚焦实战技巧与AI兴趣,助力编程爱好者成长。 7887

C语言冒泡排序:简单版+优化版+链表的冒泡排序

冒泡排序 冒泡排序(Bubble Sort),又被称为气泡排序或泡沫排序。 它是一种较简单的排序算法。它会遍历若干次要排序的数列,每次遍历时,它都会从前往后依次的比较相邻两个数的大小;如果前者比后者大,则交换它们的位置。这样,一次遍历之后,最大的元素就在数列的末尾!采用相同的方法再次遍历时,第二大的元素就被排列在最大元素之前。重复此操作,直到整个数列都有序为止! · · · 简单版–直接法 #include<stdio.h> #define N 6 void swap(int *a,int *

weixin_50545743的博客 1653

嵌入式八股文(一) C语言篇

笔者在学习时发觉自己的C语言很久没有系统性重温一遍了,本期主要是对于嵌入式中常用的C语言语法进行一个汇总。

sincerelover的博客 6587

数据结构 第八章(排序算法)【上】

(1)排序是按关键字的非递减或非递增顺序对一组记录重新进行排列的操作,如果参加排序的数据结点包含多个数据域,那么排序往往是针对其中某个域而言。(2)当待排序的序列中存在两个或两个以上关键字相等的记录时,则排序所得的结果不唯一。假设(1≤i≤n,1≤j≤n,i≠j),且在排序前的序列中领先于(即i<j),若在排序后的序列中仍领先于,则称所用的排序方法是稳定的,反之,若可能使排序后的序列中领先于,则称所用的排序方法是不稳定的。

Zevalin的博客 1690

C语言实现桶排序

1.原理,由映射函数分配初始元素的键值,然后将这些元素放入对应键值的桶中,并对桶中的数据进行排序。然后依次将每个桶中的元素分出得到排好序的序列。 2.桶排序不是基于比较的排序。将N个待排序的元素放入桶中只需要O(n)时间。后续则是对桶中元素的排序,所以当桶越多的时候,桶中的元素会越少,所采取的基于比较的排序算法的时间则会大大减少。所以,这里我们就可确定了一个重点,即是桶的数量必须是有限个的,可以经过一系列运算得到具体数目的。 3.桶的实现形式,我们以结构体数组存储单链表实现。以结构体数组的数组单元来春初链

Mpnet的博客 3096

曾经写过的代码:(1)C语言大作业之词频统计程序

用C语言编写一个简单的词频统计程序,要求如下: 1、从文件中读取一段英文短落,原样输出在控制台中; 2、统计英文短落中各类单词的数目,并输出到控制台中; 3、输出数量最多的前十个单词。

qq_28249373的博客 5638
上一篇: c语言的auto型变量是a存储在动态存储区b存储在静态存储区,c 变量的存储类型auto等(基础知识)和c函数变量...
下一篇: 2.5e2.0是合法的c语言常量,C理论自测题及参考答案(第1次)
吉利吉利
博客等级 码龄8年 31粉丝 83原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值