Big talk data structure--Simple selection sort

Source: Internet
Author: User

After learning the bubble sort, you will find that this algorithm is constantly comparing exchange. Simple and direct, obviously gives a kind of tedious feeling. Is there any better algorithm? Of course it is, no, it sucks.:-P

This article describes a better-bubbling sorting algorithm: simple selection sorting

See " Choice " The two words estimate also guessed twos. Yes, the idea of this algorithm is that I choose to swap it for the position of the most suitable digit .

In doing so, we have greatly saved a lot of unnecessary exchanges. Because swap functions are often used in code writing, they are generally encapsulated as a function for invocation. This creates a lot of unnecessary function calls if there are a lot of unnecessary switching operations. You know, the call to the function is to press the stack, so the time overhead is undoubtedly useless. So in order to find the right keyword to do the exchange, and only move once to complete the corresponding keyword sorting positioning

#include <iostream>using namespace std; #define MAX_SIZE 100//maximum value for sorting arrays typedef struct  {int r[max_size+1] ;//used to store the array to sort int length;//for the length of the Record order table}sqlist;//the value of the array element for the interchange array R subscript I and subscript j void Swap (sqlist* L, int i,int j) {int temp;temp= l->r[i]; l->r[i]=l->r[j]; L->r[j]=temp;} Simple selection Sort int Simple_selection_sort (sqlist* L) {int len=l->length;int min_number=1;for (int i=1;i!=len;++i) {Min_ number=i;for (int j=i+1;j!=len;++j) {if (l->r[min_number]>l->r[j]) min_number=j;} Swap (l,i,min_number);} return 1;} int main () {}

  

Big talk data structure--Simple selection sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.