The Beauty of Code: Exploring the Art of Sorting in C and Python

Foreword In the field of software development, it is crucial to understand and master multiple sorting algorithms. Sorting is not only a fundamental step in solving many computational problems, but in practical applications, choosing an appropriate sorting algorithm can significantly improve the performance of a program. This article will delve into techniques for sorting different […]

list.stream().sorted() Java8 Stream’s sorted() sorting. Forward order, reverse order, multi-field sorting

For collection sorting, java8 can use sorted() of the Stream stream for sorting. ExampleBeans We will use this Bean as an example below. public class Order {<!– –> private String weight; private Double price; private String dateStr; //Ignore getter, setter, constructor, toString } Field sorting The first is the comparator Comparator, which has the following […]

Java data structure (red-black tree) set collection HashSet HashSet three problems LinkedHashSetTreeSet TreeSet collection default rules sorting rules

Directory Data structure (red-black tree) red and black rules Red-black tree adding node rules set set summary HashSet Three problems with HashSet LinkedHashSet summary TreeSet TreeSet collection default rules Sorting rules (first sorting method) Method 2 practise Xiaolian Summarize Summary: How to choose when using collections Data structure (red-black tree) Red and black rules The […]

The Qsort function implements sorting of elements in various types of arrays (simple idea)

Table of Contents Function introduction Function use case: (1) Sorting of int arrays (2) Sorting of char array (3) Sorting floating-point arrays (4) Sorting of structure types (5) Imitate the function of qsort to implement a general bubble sort Function introduction Function:Quickly sort the array elements in the pointed array Header file: stdlib.h Function prototype:void […]

[Data Structure] Heap sorting and top-K problem

Heap implementation source code #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <time.h> #include <stdbool.h> #include <assert.h> typedef struct Heap {<!– –> int* a; int size; int capacity; }Heap; void HeapInit(Heap* st) {<!– –> st->a = NULL; st->capacity = 0; st->size = 0; } void swap(int* str1, int* str2) {<!– –> int tmp = *str1; *str1 […]