10.1常见的排序算法

windows中如何将已安装的nodejs高版本降级为低版本 第一步:先清空本地安装的node.js版本 1.按健win+R弹出窗口,键盘输入cmd,然后敲回车(或者鼠标直接点击电脑左面最左下角的win窗口图标弹出,输入cmd再点击回车键) 然后进入命令控制行窗口,并输入where node查看之前本地安装的node的路径 2.找到上面找到的路径,将node.exe所在的父目录里面的所有东西都删除 3.为了彻底删除之前安装的node.js,鼠标点击电脑左面最左下角的win窗口图标弹出,输入“控制面板”再点击回车键进入,进入控制面板后,找到所安装的node.js并 阅读详情

1.代码实现

/**
 * Sorting algorithms.
 * 
 * @author Fan Min minfanphd@163.com.
 */
#include <stdio.h>
#include <malloc.h>
#include <stdbool.h>

#define TABLE_SIZE 19

/**
 * <key, value> pair.
 */
typedef struct Node{
	int key;
	char value;
}Node, *NodePtr;

/**
 * <key, value> pair.
 */
typedef struct SequentialList{
	int length;
	NodePtr elements;
}SequentialList, *ListPtr;

/**
 * Initialize a data array.
 */
ListPtr initList(int* paraKeys, char* paraValues, int paraLength){
	int i;
	ListPtr resultPtr = (ListPtr)malloc(sizeof(struct SequentialList));
	resultPtr->length = paraLength;
	resultPtr->elements = (NodePtr)malloc(paraLength * sizeof(struct Node));
	for (i = 0; i < paraLength; i ++){
		//printf("setting key for index %d: %d and value: %c\r\n", i, paraKeys[i], paraValues[i]);
		resultPtr->elements[i].key = paraKeys[i];
		resultPtr->elements[i].value = paraValues[i];
	}//Of for i

	return resultPtr;
}//Of initList

/**
 * Print the list.
 */
void printList(ListPtr paraPtr) {
	int i;
	printf("(Keys, values)\r\n");
	for (i = 0; i < paraPtr->length; i ++) {
		printf("%d\t", paraPtr->elements[i].key);
	}//Of for i
	printf("\r\n");
	for (i = 0; i < paraPtr->length; i ++) {
		printf("%c\t", paraPtr->elements[i].value);
	}//Of for i
	printf("\r\n");
}//Of printList

/**
 * Insertion sort. paraPtr->elements[0] does not store a valid data. paraPtr->elements[0].key should
 * be smaller than any valid key.
 */
void insertionSort(ListPtr paraPtr) {
	Node tempNode;
	int j;
	for (int i = 2; i < paraPtr->length; i++) {
		tempNode = paraPtr->elements[i];
		
		//Find the position to insert.
		//At the same time, move other nodes.
		for (j = i - 1; paraPtr->elements[j].key > tempNode.key; j--) {
			paraPtr->elements[j + 1] = paraPtr->elements[j];
		} // Of for j
		
		//Insert.
		paraPtr->elements[j + 1] = tempNode;
	} // Of for i
}// Of insertionSort

/**
 * Test the method.
 */
void insertionSortTest() {
	int tempUnsortedKeys[] = { -100, 5, 3, 6, 10, 7, 1, 9 };
	char tempContents[] = { 'n', 'i', 't', 'e', 's', 'c', 'f', 'w' };
	ListPtr tempList = initList(tempUnsortedKeys, tempContents, 8);

	printf("\r\nBefore insertion sort:\r\n");
	printList(tempList);

	insertionSort(tempList);
	printf("\r\nAfter insertion sort:\r\n");
	printList(tempList);
}// Of insertionSortTest
 
/**
 * Shell sort.
 */
void shellSort(ListPtr paraPtr) {
	Node tempNode;
	int tempJumpArray[] = { 5, 3, 1 };
	int tempJump;
	int p, i, j, k;
	for (i = 0; i < 3; i++) {
		tempJump = tempJumpArray[i];
		for (j = 0; j < tempJump; j++) {
			for (k = j + tempJump; k < paraPtr->length; k += tempJump) {
				tempNode = paraPtr->elements[k];
				// Find the position to insert.
				// At the same time, move other nodes.
				for (p = k - tempJump; p >= 0; p -= tempJump) {
					if (paraPtr->elements[p].key > tempNode.key) {
						paraPtr->elements[p + tempJump] = paraPtr->elements[p];
					} else {
						break;
					} // Of if
				} // Of for p

				// Insert.
				paraPtr->elements[p + tempJump] = tempNode;
			} // Of for k
		} // Of for j
	} // Of for i
}// Of shellSort

/**
 * Test the method.
 */
void shellSortTest() {
	int tempUnsortedKeys[] = {5, 3, 6, 10, 7, 1, 9 };
	char tempContents[] = {'i', 't', 'e', 's', 'c', 'f', 'w' };
	ListPtr tempList = initList(tempUnsortedKeys, tempContents, 7);

	printf("\r\nBefore shell sort:\r\n");
	printList(tempList);

	shellSort(tempList);
	printf("\r\nAfter shell sort:\r\n");
	printList(tempList);
}// Of shellSortTest

/**
 * Bubble sort.
 */
void bubbleSort(ListPtr paraPtr) {
	bool tempSwapped;
	Node tempNode;
	int i, j;
	for (i = paraPtr->length - 1; i > 0; i--) {
		tempSwapped = false;
		for (j = 0; j < i; j++) {
			if (paraPtr->elements[j].key > paraPtr->elements[j + 1].key) {
				// Swap.
				tempNode = paraPtr->elements[j + 1];
				paraPtr->elements[j + 1] = paraPtr->elements[j];
				paraPtr->elements[j] = tempNode;

				tempSwapped = true;
			} // Of if
		} // Of for j

		// No swap in this round. The data are already sorted.
		if (!tempSwapped) {
			printf("Premature.\r\n");
			break;
		} // Of if
	} // Of for i
}// Of bubbleSort

/**
 * Test the method.
 */
void bubbleSortTest() {
	int tempUnsortedKeys[] = {5, 3, 6, 10, 7, 1, 9 };
	char tempContents[] = {'i', 't', 'e', 's', 'c', 'f', 'w' };
	ListPtr tempList = initList(tempUnsortedKeys, tempContents, 7);

	printf("\r\nBefore bubble sort:\r\n");
	printList(tempList);

	shellSort(tempList);
	printf("\r\nAfter bubble sort:\r\n");
	printList(tempList);
}// Of bubbleSortTest

/**
 * Quick sort recursive.
 */
void quickSortRecursive(ListPtr paraPtr, int paraStart, int paraEnd) {
	int tempPivot, tempLeft, tempRight;
	Node tempNodeForSwap;
	
	// Nothing to sort.
	if (paraStart >= paraEnd) {
		return;
	} // Of if

	tempPivot = paraPtr->elements[paraEnd].key;
	
	tempLeft = paraStart;
	tempRight = paraEnd - 1;

	// Find the position for the pivot.
	// At the same time move smaller elements to the left and bigger one to the
	// right.
	while (true) {
		while ((paraPtr->elements[tempLeft].key < tempPivot) && (tempLeft < tempRight)) {
			tempLeft++;
		} // Of while

		while ((paraPtr->elements[tempRight].key >= tempPivot) && (tempLeft < tempRight)) {
			tempRight--;
		} // Of while

		if (tempLeft < tempRight) {
			// Swap.
			//System.out.println("Swapping " + tempLeft + " and " + tempRight);
			tempNodeForSwap = paraPtr->elements[tempLeft];
			paraPtr->elements[tempLeft] = paraPtr->elements[tempRight];
			paraPtr->elements[tempRight] = tempNodeForSwap;
		} else {
			break;
		} // Of if
	} // Of while

	// Swap
	if (paraPtr->elements[tempLeft].key > tempPivot) {
		tempNodeForSwap = paraPtr->elements[paraEnd];
		paraPtr->elements[paraEnd] = paraPtr->elements[tempLeft];
		paraPtr->elements[tempLeft] = tempNodeForSwap;
	} else {
		tempLeft++;
	} // Of if

	//System.out.print("From " + paraStart + " to " + paraEnd + ": ");
	//System.out.println(this);

	quickSortRecursive(paraPtr, paraStart, tempLeft - 1);
	quickSortRecursive(paraPtr, tempLeft + 1, paraEnd);
}// Of quickSortRecursive

/**
 * Quick sort.
 */
void quickSort(ListPtr paraPtr) {
	quickSortRecursive(paraPtr, 0, paraPtr->length - 1);
}// Of quickSort

/**
 * Test the method.
 */
void quickSortTest() {
	int tempUnsortedKeys[] = {5, 3, 6, 10, 7, 1, 9 };
	char tempContents[] = {'i', 't', 'e', 's', 'c', 'f', 'w' };
	ListPtr tempList = initList(tempUnsortedKeys, tempContents, 7);

	printf("\r\nBefore quick sort:\r\n");
	printList(tempList);

	quickSort(tempList);
	printf("\r\nAfter quick sort:\r\n");
	printList(tempList);
}// Of quickSortTest

/**
 * Selection sort.
 */
void selectionSort(ListPtr paraPtr) {
	Node tempNode;
	int tempIndexForSmallest, i, j;

	for (i = 0; i < paraPtr->length - 1; i++) {
		// Initialize.
		tempNode = paraPtr->elements[i];
		tempIndexForSmallest = i;
		for (j = i + 1; j < paraPtr->length; j++) {
			if (paraPtr->elements[j].key < tempNode.key) {
				tempNode = paraPtr->elements[j];
				tempIndexForSmallest = j;
			} // Of if
		} // Of for j

		// Change the selected one with the current one.
		paraPtr->elements[tempIndexForSmallest] = paraPtr->elements[i];
		paraPtr->elements[i] = tempNode;
	} // Of for i
}// Of selectionSort

/**
 * Test the method.
 */
void selectionSortTest() {
	int tempUnsortedKeys[] = {5, 3, 6, 10, 7, 1, 9 };
	char tempContents[] = {'i', 't', 'e', 's', 'c', 'f', 'w' };
	ListPtr tempList = initList(tempUnsortedKeys, tempContents, 7);

	printf("\r\nBefore selection sort:\r\n");
	printList(tempList);

	selectionSort(tempList);
	printf("\r\nAfter selection sort:\r\n");
	printList(tempList);
}// Of selectionSortTest

/**
 * Adjust heap.
 */
void adjustHeap(ListPtr paraPtr, int paraStart, int paraLength) {
	Node tempNode = paraPtr->elements[paraStart];
	int tempParent = paraStart;
	int tempKey = paraPtr->elements[paraStart].key;

	for (int tempChild = paraStart * 2 + 1; tempChild < paraLength; tempChild = tempChild * 2 + 1) {
		// The right child is bigger.
		if (tempChild + 1 < paraLength) {
			if (paraPtr->elements[tempChild].key < paraPtr->elements[tempChild + 1].key) {
				tempChild++;
			} // Of if
		} // Of if

		printf("The parent position is %d and the child is %d.\r\n", tempParent, tempChild);
		if (tempKey < paraPtr->elements[tempChild].key) {
			// The child is bigger.
			paraPtr->elements[tempParent] = paraPtr->elements[tempChild];
			printf("Move %d to position %d.\r\n", paraPtr->elements[tempChild].key, tempParent);
			tempParent = tempChild;
		} else {
			break;
		} // Of if
	} // Of for tempChild

	printf("Move %d to position %d.\r\n", tempNode.key, tempParent);
	paraPtr->elements[tempParent] = tempNode;
}// Of adjustHeap
 
 /**
 * Heap sort.
 */
void heapSort(ListPtr paraPtr) {
	Node tempNode;
	int i;
	// Step 1. Construct the initial heap.
	for (i = paraPtr->length / 2 - 1; i >= 0; i--) {
		adjustHeap(paraPtr, i, paraPtr->length);
	} // Of for i

	// Step 2. Swap and reconstruct.
	for (i = paraPtr->length - 1; i > 0; i--) {
		tempNode = paraPtr->elements[0];
		paraPtr->elements[0] = paraPtr->elements[i];
		paraPtr->elements[i] = tempNode;

		adjustHeap(paraPtr, 0, i);
		printf("Round %d : ", (paraPtr->length - i));
		printList(paraPtr);
	} // Of for i
}// Of heapSort

/**
 * Test the method.
 */
void heapSortTest() {
	int tempUnsortedKeys[] = {5, 3, 6, 10, 7, 1, 9 };
	char tempContents[] = {'i', 't', 'e', 's', 'c', 'f', 'w' };
	ListPtr tempList = initList(tempUnsortedKeys, tempContents, 7);

	printf("\r\nBefore heap sort:\r\n");
	printList(tempList);

	heapSort(tempList);
	printf("\r\nAfter heap sort:\r\n");
	printList(tempList);
}// Of heapSortTest

/**
 * Selection sort.
 */
void mergeSort(ListPtr paraPtr) {
	// Step 1. Allocate space.

	int tempRow; // The current row
	int tempGroups; // Number of groups
	int tempActualRow; // Only 0 or 1
	int tempNextRow = 0;
	int tempGroupNumber;
	int tempFirstStart, tempSecondStart, tempSecondEnd;
	int tempFirstIndex, tempSecondIndex;
	int tempNumCopied;
	int i;
	int tempSize;

	/*
	ListPtr tempMatrix[2];
	int* tempIntArray = (int*)malloc(paraPtr->length * sizeof(int));
	char* tempCharArray = (char*)malloc(paraPtr->length * sizeof(char));
	tempMatrix[0] = paraPtr;
	tempMatrix[1] = initList(tempIntArray, tempCharArray, paraPtr->length);
	*/

	Node** tempMatrix = (Node**)malloc(2 * sizeof(Node*));
	tempMatrix[0] = (Node*)malloc(paraPtr->length * sizeof(Node));
	tempMatrix[1] = (Node*)malloc(paraPtr->length * sizeof(Node));
	for (i = 0; i < paraPtr->length; i ++) {
		tempMatrix[0][i] = paraPtr->elements[i];
	}//Of for i

	/*
	Node tempMatrix[2][length];

	// Step 2. Copy data.
	for (i = 0; i < length; i++) {
		tempMatrix[0][i] = data[i];
	} // Of for i
	*/

	// Step 3. Merge. log n rounds
	tempRow = -1;
	for (tempSize = 1; tempSize <= paraPtr->length; tempSize *= 2) {
		// Reuse the space of the two rows.
		tempRow++;
		//System.out.println("Current row = " + tempRow);
		tempActualRow = tempRow % 2;
		tempNextRow = (tempRow + 1) % 2;

		tempGroups = paraPtr->length / (tempSize * 2);
		if (paraPtr->length % (tempSize * 2) != 0) {
			tempGroups++;
		} // Of if
		//System.out.println("tempSize = " + tempSize + ", numGroups = " + tempGroups);

		for (tempGroupNumber = 0; tempGroupNumber < tempGroups; tempGroupNumber++) {
			tempFirstStart = tempGroupNumber * tempSize * 2;
			tempSecondStart = tempGroupNumber * tempSize * 2 + tempSize;
			if (tempSecondStart > paraPtr->length - 1) {
				// Copy the first part.
				for (i = tempFirstStart; i < paraPtr->length; i++) {
					tempMatrix[tempNextRow][i] = tempMatrix[tempActualRow][i];
				} // Of for i
				continue;
			} // Of if
			tempSecondEnd = tempGroupNumber * tempSize * 2 + tempSize * 2 - 1;
			if (tempSecondEnd > paraPtr->length - 1) {
				tempSecondEnd = paraPtr->length - 1;
			} // Of if

			tempFirstIndex = tempFirstStart;
			tempSecondIndex = tempSecondStart;
			tempNumCopied = 0;
			while ((tempFirstIndex <= tempSecondStart - 1)
					&& (tempSecondIndex <= tempSecondEnd)) {
				if (tempMatrix[tempActualRow][tempFirstIndex].key <= tempMatrix[tempActualRow][tempSecondIndex].key) {

					tempMatrix[tempNextRow][tempFirstStart
							+ tempNumCopied] = tempMatrix[tempActualRow][tempFirstIndex];
					tempFirstIndex++;
					//System.out.println("copying " + tempMatrix[tempActualRow][tempFirstIndex]);
				} else {
					tempMatrix[tempNextRow][tempFirstStart
							+ tempNumCopied] = tempMatrix[tempActualRow][tempSecondIndex];
					//System.out.println("copying " + tempMatrix[tempActualRow][tempSecondIndex]);
					tempSecondIndex++;
				} // Of if
				tempNumCopied++;
			} // Of while

			while (tempFirstIndex <= tempSecondStart - 1) {
				tempMatrix[tempNextRow][tempFirstStart
						+ tempNumCopied] = tempMatrix[tempActualRow][tempFirstIndex];
				tempFirstIndex++;
				tempNumCopied++;
			} // Of while

			while (tempSecondIndex <= tempSecondEnd) {
				tempMatrix[tempNextRow][tempFirstStart
						+ tempNumCopied] = tempMatrix[tempActualRow][tempSecondIndex];
				tempSecondIndex++;
				tempNumCopied++;
			} // Of while
		} // Of for groupNumber

	} // Of for tempStepSize

	for (i = 0; i < paraPtr->length; i ++) {
		paraPtr->elements[i] = tempMatrix[tempNextRow][i];
	}//Of for i
}// Of mergeSort

/**
 * Test the method.
 */
void mergeSortTest() {
	int tempUnsortedKeys[] = {5, 3, 6, 10, 7, 1, 9 };
	char tempContents[] = {'i', 't', 'e', 's', 'c', 'f', 'w' };
	ListPtr tempList = initList(tempUnsortedKeys, tempContents, 7);

	printf("\r\nBefore merge sort:\r\n");
	printList(tempList);

	mergeSort(tempList);
	printf("\r\nAfter merge sort:\r\n");
	printList(tempList);
}// Of mergeSortTest
 
 /**
 * The entrance of the program.
 */
int main() {
	insertionSortTest();
	//shellSortTest();
	//bubbleSortTest();
	//quickSortTest();
	//selectionSortTest();
	//heapSortTest();
	//mergeSortTest();
	return 1;
}// Of main

2.插入排序的结果输出

代码如下(示例):

Before insertion sort:
(Keys, values)
-100    5       3       6       10      7       1       9
n       i       t       e       s       c       f       w

After insertion sort:
(Keys, values)
-100    1       3       5       6       7       9       10
n       f       t       i       e       c       w       s
【推荐100个unity插件】将UE的资源导出到unity使用—— Exporter for Unreal to/for Unity插件 Unreal to Unity导出器是一款帮助开发者将Unreal Engine项目转换为Unity的工具。文章详细介绍了使用步骤:1)安装虚幻引擎并创建项目;2)在Plugins文件夹中安装导出插件;3)导入UE资产到Content文件夹;4)配置导出参数并完成转换。文末推荐了多个Unity开发专栏,涵盖C#编程、2D/3D开发、特效制作等内容。作者向宇提供了博客地址,欢迎读者交流学习。该工具能有效提升项目迁移效率,适合需要跨引擎开发的用户使用。 阅读详情

相关推荐

基于YOLOv8-obb的自动车牌检测与CRNN车牌识别

基于YOLOv8-obb模型实现了针对带角度车牌的自动检测,并结合CRNN(Convolutional Recurrent Neural Network)技术进行车牌字符识别,旨在提高复杂场景下车牌识别系统的准确性和鲁棒性

坚强的强酸柠檬的博客 1146

10.1: 常见的排序算法

***//***/int key;char value;/***/int length;/***/int i;for (i = 0;i ++){/***/int i;for (i = 0;i ++) {for (i = 0;i ++) {/***/int j;i++) {j--) {

2301_81046562的博客 494

基于STM32F407的摄像头(不带FIFO的OV7670)图像采集及LCD显示实验-笔记整理

硬件说明 STM32F4开发板 stm32f4系列的芯片处理的能力可以说非常强大了的,而且内部还自带有数字摄像头接口(DCMI),可以说stm32f407的核心板和不带FIFO的摄像头模块OV7670简直就是绝配! 我手上的这块张这个样子 (图片来源:某宝): F4系列的DCMI接口内部结构框图如下图3所示,具体的配置使用方式可以参考以下这篇博文:《stm32f4的数字摄像头接口(DCMI)使用》 这位博主大大已经很详细地介绍了DCMI接口的具体使用方法和原理,更重要的是里面还有接口的配置函数,虽然不完

LiangWF22的博客 2万+

数据结构 C 代码 10.1: 常见的排序算法

摘要: 排序算法最能体现算法的多样性。

minfanphd的博客 1245

小案例:利用图床自动化批量上传图片并获取图片链接

用python爬虫写了一个小脚本,用来自动上传图片到图床,然后返回链接,我们只需直接复制链接就可以。(需要安装Requests库) 因为不同图床需要提交的POST表单不一致,所以在这里我用ImgURL图床做示范,如果大家有需求,可自行修改代码。使用脚本的时候,我们只需把需要上传的图片和这个脚本放在同一个文件夹中,然后运行脚本,稍作等待,看到提示时就可以在脚本运行文件夹中发现一个名为“图片链接地址.txt”的文件,里面就是图片链接啦! 四、图片链接地址.txt(单张图片):...

采菊东篱下,Python满乾坤! 4415

基于Java+SpringBoot+Vue的中小企业设备管理系统的设计与开发(源码+lw+部署文档+讲解等)

💗博主介绍:✌新人博主,工作经验两年+、专注于Java、小程序技术领域和毕业项目实战✌💗🌟文末获取源码+数据库🌟

2301_76502068的博客 1385

算法-20521_1.10种常见的排序算法

https://www.cnblogs.com/flyingdreams/p/11161157.html https://www.cnblogs.com/zmkblog/p/8638457.html

qq_28613081的博客 196

广东电信兆能Z82盒子救砖记:手把手教你用U盘强刷HI3798MV100固件(附短接图)

本文详细介绍了广东电信兆能Z82盒子变砖后的救砖方法,重点讲解了使用U盘强刷HI3798MV100固件的全流程,包括诊断、准备工作、短接操作及刷机后的优化设置。特别针对m8233主板和8188无线方案的机型,提供了实用的短接图和操作技巧,帮助用户成功恢复设备。

weixin_30325487的博客 405

【作业】10.1: 常见的排序算法

【代码】【作业】10.1: 常见的排序算法。

crazzyy的博客 387

ControlCAN.dll开发适配USBCAN_E/2E_U设备

摘要:本文提供了USBCAN_E/2E_U设备的配置指南:1)安装专用驱动;2)获取最新的ControlCAN.dll文件;3)修改VCI调用顺序,新增VCI_SetReference函数设置波特率;4)使用工具计算波特率配置值,并给出了常见波特率对应的代码参考值(如500K对应0x060007)。配置过程强调使用特定工具计算精确的波特率参数,并提供了相关软件下载链接。

weixin_43969033的博客 392

VN5620以太网测试——DoIP配置

CANoe(CAN open environment)VN5620 :是一个紧凑而强大的接口,用于以太网网络的分析、仿真、测试和验证。VN5620 接口支持各种可能的应用。它适用于与其他总线系统、网络参与(例如在模拟和生成帧、测试中的负载和错误)的同步以太网监控。在2021年Vector公司的以太网接口卡VN5610和VN5640设备已经陆续停产,相应被VN5620和VN5650代替。参考文章了解DoIP协议——汽车以太网应用介绍。

诊断协议那些事儿's blog 3017

Go将在下个版本支持pdqsort排序算法

继Go 1.18支持泛型后,Go 将在下个版本中支持pdqsort排序算法再次引起了开发者们的热切讨论。 目前,Go仓库的最新commit中提交了pdqsort的相关功能描述: 在所有基准测试中,pdqsort未表现出比以前的其它算法慢; 在常见模式中,pdqsort通常更快(即在排序切片中快10倍) 那么pdqsort是什么呢? pdqsort是Pattern-defeating quicksort的缩写,是一种新型的排序算法,将随机快速排序的快速平均情况与堆排序的最坏情况快速组合在一起,同时在具有特

wouderw的博客 250

宽压 DC⇌DC 也能“随心所欲”——全桥 LLC 混合控制硬核拆解

硬件派 vs. 软件派:多电平是“器件堆砌”,混合控制是“算法魔改”。预算紧 → 先搞软件。仿真别嫌烦:PLECS 把两条曲线扫透,切换点、死区、φ 都调到波形平滑再上板。温升留 20 ℃ 余量:车规≥125 ℃,实验室测 105 ℃ 就算危险,别玩极限。

weixin_43199439的博客 929

常见的10种排序算法

介绍常用的10种排序算法

懒猫的脚印 3万+

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

常见的排序算法的时间复杂度

接着,对每个桶中的元素进行排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序),最后依次将各个桶中的元素取出,得到的就是有序序列。计数排序不是基于比较的排序算法,其优势在于在对一定范围内的整数排序时,复杂度为O(n+k),其中n为输入元素个数,k为待排序列中最大的数。例如,如果数据的范围非常大,或者数据的分布极不均匀,那么可能需要大量的桶,这可能导致空间复杂度的增加。基数排序的时间复杂度是线性的,为O(dn),其中d为数字的位数,n为待排序序列的长度。因此,时间复杂度为O(n^2)。

码字不易,大家的支持就是我坚持下去的动力 2万+

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

排序算法—10种常见排序算法的原理以及Java代码的实现【两万字】

10种常见排序算法的原理,包括冒泡排序、选择排序、插入排序、希尔排序、堆排序、归并排序、快速排序、计数排序、桶排序、基数排序。并且每种排序都提供了Java代码的实现案例。

终生学习践行者 5104

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

十种常见排序算法

0、算法概述 0.1 算法分类 十种常见排序算法可以分为两大类: 比较类排序:通过比较来决定元素间的相对次序,由于其时间复杂度不能突破O(nlogn),因此也称为非线性时间比较类排序。 非比较类排序:不通过比较来决定元素间的相对次序,它可以突破基于比较排序的时间下界,以线性时间运行,因此也称为线性时间非比较类排序。 0.2 算法复杂度 0.3 相关概念 稳定:如果a原本在b前面,而a=b,排序之后a仍然在b的前面。 不稳定:如果a原本在b的前面,而a=b,排序之后 a 可能会出现在 .

liyongchunscr的博客 1万+

常见排序算法小结

     排序算法经过了很长时间的演变,产生了很多种不同的方法。对于初学者来说,对它们进行整理便于理解记忆显得很重要。每种算法都有它特定的使用场合,很难通用。因此,我们很有必要对所有常见的排序算法进行归纳。      我不喜欢死记硬背,我更偏向于弄清来龙去脉,理解性地记忆。比如下面这张图,我们将围绕这张图来思考几个问题。      上面的这张图来自一个PPT。它概括了数据结构中的所有常见的排序算法。现在有以下几个问题:      1、每个算法的思想是什么?      2、每个算法的稳定

Simple life 11万+

常见的七种排序算法

目录 1.排序算法的概念及其运用 1.1 排序的概念 1.2 排序运用 1.3 常见的排序算法 2.常见排序算法的实现 2.1 插入排序 2.1.1直接插入排序 2.1.2 希尔排序(缩小增量排序) 2.2 选择排序 2.2.1 直接选择排序 2.2.2 堆排序 2.3 交换排序 2.3.1 冒泡排序 2.3.2 快速排序 2.4 归并排序 3.排序算法复杂度及稳定性分析 1.排序算法的概念及其运用 1.1 排序...

m0_58367586的博客 3312

彻底搞懂10种常见排序算法(附代码)

在程序员的世界里,排序算法无处不在。无论是开发面试、还是日常工程实践,排序都是基本功之一。今天,我将用最通俗易懂的方式,带你全面掌握10种常见排序算法,每种算法都配上了Python代码示例和详细讲解,帮你从入门到精通!

2301_76849350的博客 2748

常见的排序算法

在开发语言中实现的排序算法种类繁多,且每种算法都有其特定的应用场景和优化空间,因此在这里我会列出一些常见的排序算法。这些算法的性能在不同的数据集和使用场景下会有所不同。选择合适的排序算法取决于数据的特性、内存限制以及性能要求。例如,对于小数据集,简单直观的排序算法(如冒泡排序或插入排序)可能就足够了;对于大数据集,则可能需要使用更高效的算法(如归并排序、快速排序或堆排序)。对于特定类型的数据(如整数且范围较小),计数排序、桶排序或基数排序可能会更有效。

zam520的博客 1000

常见排序算法详解

排序是我们在日常生活和工作中常见的一种操作。在计算机科学中,排序算法就是将一串或一组数据按照特定的顺序进行排列的算法。这些顺序可能是数字的升序或降序,也可能是字母或字词的字母顺序等。我们将探讨几种不同的排序算法,包括他们的原理、优缺点以及代码实现。常见的排序算法包括:冒泡排序、快速排序、插入排序、选择排序、希尔排序、归并排序、堆排序、基数排序等。这些排序算法中,有些是比较排序,即通过比较元素之间的关系进行排序;

沐雨风栉 875

10种常见排序算法总结

快排可能存在最坏情况,需要把枢轴值选取得尽量随机化来缓解最坏情况下的时间复杂度。插入排序对于近乎有序的数据处理速度比较快,复杂度有所下降,可以提前结束。gap序列的构造有多种方式,不同方式处理的数据复杂度可能不同。对于整个数组或非最左侧 size > 4096,有序度高。不稳定:排序前后有可能会将值相同的元素的顺序打乱。堆排序的辅助性较强,理解前先理解堆的数据结构。稳定:排序前后不会将值相同的元素的顺序打乱。需要额外的O(n)的存储空间。交换次数一般少于冒泡。递归次数超过 384。递归次数超过 384。

埃泽漫笔 1225

常见排序算法

目录 一,排序算法 1,分类方法 (1)内部排序、外部排序 (2)原址排序、非原址排序 (3)稳定排序、非稳定排序 (4)基于计算的排序算法、基于比较的排序算法 2,排序算法测试代码 (1)提供模板函数 (2)约定接口 (3)排序测试 3,常见排序算法 (1)插入排序 (2)选择排序 (3)冒泡排序 (4)归并排序 (5)堆排序 (6)快速排序 (7)基数排序 (8)计数排序 (9)桶排序 (10)希尔排序 二,排序算法效率、组合嵌套 三,sort 四,拓展排

nameofcsdn的博客 2444

10种排序算法详解及其代码实现

排序算法是计算机科学中的经典算法问题之一。排序算法根据不同的排序原理和实现方式有着不同的时间复杂度、空间复杂度和适用场景。以下是常见的10种排序算法的详解和代码实现,涵盖了从简单的交换排序到更高效的归并排序、快速排序等算法。

软件开发工程师 1340

10种基本排序算法

文章目录排序算法分类各排序算法复杂度分析(一)冒泡排序(Bubble Sort)算法描述(二)快速排序(Quick Sort)算法描述(三)、简单插入排序(Insertion Sort)算法描述(四)、希尔排序(Shell Sort)算法描述(五)、简单选择排序(Selection Sort)算法描述(六)、堆排序(Heap Sort)(七)、归并排序(Merge Sort)算法描述(八)、计数排序(Counting Sort)算法描述(九)、桶排序(Bucket sort)(十)、基数排序(Radix S

Lenjor 的博客 3564
上一篇: 7.1图的遍历
dev_cc_
博客等级 码龄3年 41粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值