1.Bubble Sort
Bubble Sort (Bubble Sort) is the simplest kind of sorting. It goes through all the elements of the array repeatedly. Elements are compared two by two in a ring, until the number is ended when there are no more numbers to exchange, and then the next number is added until the entire array is sorted. Because they float one by one, it is called bubble sort. Double cycle time O(n^2)
Algorithm description:
Compare two adjacent data if. The first one is greater than the second one, just swap the two numbers
Do the same 1 work for each adjacent number, so that from the beginning to the end, one team is at the end The number is the largest number.
Operations on all elements except the last one.
Repeat steps 1~3 until the order is completed.
Code visualization:
##Code implementation:
2. Selection Sort
Select Sort is an intuitive sorting, by determining the maximum or minimum value of a Key, and then sorting from the band Find the largest or smallest number and swap it to the corresponding position. Choose the next best option. The double loop time complexity is O(n^2)Algorithm description:
- In an unordered sequence of length N In the array, traverse n-1 numbers for the first time to find the smallest one and exchange it with the first number.
- Traverse n-2 numbers starting from the next number for the second time, find the smallest number and exchange it with the second number.
- Repeat the above operation until the smallest number and the n-1th number are exchanged for the n-1th traversal, and the sorting is completed.
Algorithm visualization:
3. Quick Sort<code><p><img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/164/168309619043778.png?x-oss-process=image/resize,p_40" class="lazy" alt="How to implement bubble sort, selection sort, quick sort in Java"><br></p></code>
Quick Sort (QuickSort) is the most commonly used sort after excluding stability factors. I would like to introduce two ways to use it. One is to implement the qsort function directly in the header file of my stdlib.h file, which is the same as writing normal code. Array sorting is implemented by using qsort (array name, length, sizeof (first number length), compInc/comoDec). The latter is in the form of recursive calls.
Algorithm description:- Select an element from the sequence as the benchmark.
- Rearrange the sequence, put all the ones smaller than the benchmark in front of the benchmark, and put them in the back (the same size can be on either side). After completion, the benchmark will be in the middle of the partition.
- Sort the subsequences that are smaller than the base element and the heavy rain base element through recursive calls.
## Code implementation:
The above is the detailed content of How to implement bubble sort, selection sort, quick sort in Java. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于PriorityQueue优先级队列的相关知识,Java集合框架中提供了PriorityQueue和PriorityBlockingQueue两种类型的优先级队列,PriorityQueue是线程不安全的,PriorityBlockingQueue是线程安全的,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于java锁的相关问题,包括了独占锁、悲观锁、乐观锁、共享锁等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

封装是一种信息隐藏技术,是指一种将抽象性函式接口的实现细节部分包装、隐藏起来的方法;封装可以被认为是一个保护屏障,防止指定类的代码和数据被外部类定义的代码随机访问。封装可以通过关键字private,protected和public实现。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于平衡二叉树(AVL树)的相关知识,AVL树本质上是带了平衡功能的二叉查找树,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
