Tag:Bubble sort

  • Implementation of BubbleSort in C + +


    This example for you to share the C + + bubble sort specific code, for your reference, the specific content is as follows 1、 Thinking: Bubble sort algorithm principle: 1. Compare the adjacent elements. If the first number is larger than the second number, exchange them. 2. Do the same work for each pair of […]

  • Ruby based insertion and bubble sorting algorithms


    1. Insert sort Copy codeThe code is as follows: seq = [3,4,9,0,2,5,9,7,1] 1.upto(seq.length-1) do |i|  if seq[i] < seq[i-1]    tmp = seq[i]    j = i-1    while(j>=0 && tmp<seq[j]) do      seq[j+1] = seq[j]      j=j-1    end    seq[j+1]=tmp  endend seq.each {|num| puts num} 2. Bubble sorting Copy codeThe code is as follows: seq = [3,4,9,0,2,5,9,7,1,100,99,24,64,18,88,66] 0.upto(seq.length-1) do |i|  […]

  • The implementation of bubbling sort method in C language (ascending sort method)


    Task Code: Sorting of numbers: #include <stdio.h> #define SIZE 10 int main() { Int a [size] = {12, 43, 9, 13, 67, 98101, 89, 3, 35}; // disordered series of ten numbers int i,j,t; Printf (“this program uses bubble sorting to arrange the unordered sequence! \n “”; //Bubble sorting For (I = 0; I < […]

  • An example of advanced play method for. Net set sorting


    Preface This article mainly introduces another advanced play method of. Net set sorting. The example code is introduced in detail in this article. You can refer to and learn from it if you need. Let’s have a look at the detailed introduction Background: Students have names and student numbers, Class name and serial number The […]

  • Example code of bubble sort, merge sort and fast sort in Scala


    1. Bubble sorting def sort(list: List[Int]): List[Int] = list match { case List() => List() case head :: tail => compute(head, sort(tail)) } def compute(data: Int, dataSet: List[Int]): List[Int] = dataSet match { case List() => List(data) case head :: tail => if (data <= head) data :: dataSet else head :: compute(data, tail) } […]

  • Python algorithm and bubble sorting of data structure


    Introduction to Bubble Sorting Bubble Sort is a simple sorting algorithm. It iterates through the columns to be sorted, comparing two elements at a time, and swapping them if their order is wrong. The work of traversing a sequence is repeated until no exchange is needed, that is to say, the sequence has been sorted. […]

  • Graphical Notes of Algorithms Recursion


    Recursion is an interesting concept. As mentioned earlier, recursion can greatly improve the readability of algorithms, and it is usually better than using circular structures to write accurate algorithms. The image of this book is recursive, not too deep, so I did a little “add fuel and vinegar”. recursion concept Recursion is actually self-invoking. Recursive […]

  • Bubble Sorting Algorithms and Simple Implementation of Ruby Edition


    Algorithmic principles: Compare adjacent elements. If the first one is bigger than the second one, exchange the two.Do the same work for each pair of adjacent elements, from the first pair at the beginning to the last pair at the end. At this point, the last element should be the largest number.Repeat the above steps […]