<> One , Data structure overview

<>【1】 Introduction to data structure

Data structure is a kind of operation object in the programming problem of non numerical calculation , And their relationship and operation and other related issues

<>【2】 Data structure classification

<> The data structure is divided into Logical structure and Physical structure Two types

<> Classification of logical structure :

* 1, Set structure : In the set structure, data elements belong to the same collection except for , There is no other relationship between them
* 2, linear structure : There is a one-to-one relationship between data elements in linear structure
* 3, tree structure : There is a one to many hierarchical relationship between data elements in tree structure
* 4, Graphic structure : The data elements of graph structure are many to many relations
<> Classification of physical structure :

The real representation of logical structure in computer ( Also called image ) It's called physical structure , It can also be called storage structure . Common physical structures are Sequential storage structure , Linked Storage Structure

* The most commonly used sequential storage structure is array
* The most commonly used chain storage structure is linked list
<> Two , Simple sort

<>【1】 Bubble sort
/** * Time complexity :O(n^2) * * Realization of bubble sort : * 1. Compare each element to the next from left to right *
2. Each round determines the largest or smallest element in an unordered element , Placed at the end or beginning of an array */ public class Bubble sort { public static void
main(String[] args) { Integer[] arr = {3, 1, 5, 2, 4, 4, 9, 8, 7};
Bubble.sort(arr); System.out.println(Arrays.toString(arr)); } } class Bubble {
public static void sort(Integer[] t) { Integer temp; for (int i = 1; i <
t.length; i++) { for (int j = 0; j < t.length - i; j++) { if (t[j] > t[j + 1])
{ temp = t[j]; t[j] = t[j + 1]; t[j + 1] = temp; } } } } }
<>【2】 Select sort
/** * Time complexity :O(n^2) * * How to realize selective sorting : * 1. Compare each element to the next *
2. Each round determines the minimum value of an unordered element , Place the minimum value at the beginning or end */ public class Select sort { public static void
main(String[] args) { Integer[] arr = {3, 1, 5, 2, 4, 4, 9, 8, 7};
Selection.sort(arr); System.out.println(Arrays.toString(arr)); } } class
Selection { public static void sort(Integer[] arr) { Integer minindex; Integer
temp; for (int i = 0; i < arr.length - 1; i++) { minindex = i; for (int j = i +
1; j < arr.length; j++) { if(arr[j] < arr[minindex]){ minindex = j; } } temp =
arr[i]; arr[i] = arr[minindex]; arr[minindex] = temp; } } }
<>【3】 Insert sort
/** * Time complexity :O(n^2) * * Implementation of insertion sort : *
1. Divide the array into sorted and unsorted segments , The initial default array is the first element in the sort , The remaining elements are unsorted *
2. From index to 1 start , Each round uses reverse order to compare the first element in the unsorted with all elements in the sort * 3. If the unsorted element is smaller than the sorted element , Exchange element size , Otherwise, stop the cycle
*/ public class Insert sort { public static void main(String[] args) { Integer[] arr =
{3, 1, 5, 2, 4, 4, 9, 8, 7}; Insertion.sort(arr);
System.out.println(Arrays.toString(arr)); } } class Insertion { public static
void sort(Integer[] arr) { Integer temp; for (int i = 1; i < arr.length; i++) {
for (int j = i; j > 0; j--) { if(arr[j] < arr[j - 1]){ temp = arr[j - 1]; arr[j
- 1] = arr[j]; arr[j] = temp; }else{ break; } } } } }

Technology
©2019-2020 Toolsou All rights reserved,
Java Swing JList: List box components Accurate mobile phone number capture , Big data of operators The difference between memory overflow and memory leak , Causes and Solutions Website mobile phone number capture method stay Vue Use in Web Worker3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! What's the difference in server prices ? Basic definition and use of function ‘ To be continued SQL Server Database Glossary Chrome OS, For programmers and Windows What does it mean ? Internet Marketing