C language selection, bubbling, insertion sorting algorithm

Source: Internet
Author: User

#include <stdio.h>

#pragma mark selection sorting algorithm

void Xuanze_array (int *array, int len)

{

for (int i = 0; i<len-1; i++) {

for (int j = i+1; j<len; j + +) {

if (Array[i]<array[j]) {

int temp = Array[i];

Array[i] = Array[j];

ARRAY[J] = temp;

}

}

}

}

#pragma mark bubble sorting algorithm

void Maopao_array (int *array, int len)

{

for (int i = 0; i<len-1; i++) {

for (int j = 0; j<len-i-1; j + +) {

if (Array[j]>array[j+1]) {

int temp = Array[j];

ARRAY[J] = array[j+1];

ARRAY[J+1] = temp;

ARRAY[J] = Array[j+1]-array[j];

ARRAY[J+1] = array[j+1]-array[j];

ARRAY[J] = Array[j+1]+array[j];

}

}

}

}

#pragma mark insertion sorting algorithm

void Insert_array (int *array, int len)

{

for (int i = 1; i<len; i++) {

int temp = Array[i];

int j = i-1;

while (Temp<array[j]) {

ARRAY[J+1] = Array[j];

j--;

if (j==-1) {

Break

}

}

ARRAY[J+1] = temp;

}

}

#pragma mark Traversal array

void Print_array (int *array, int len)

{

for (int i = 0; i<len; i++)

{

printf ("%d\t", Array[i]);

}

printf ("\ n");

}

int main ()

{

Define an array

int array[] = {24, 14, 8, 66, 3, 9, 22};

The length of an array of arrays

int len = sizeof (array)/sizeof (int);

Insert_array (array, len);

Maopao_array (array, len);

Xuanze_array (array, len);

Output array

Print_array (array, len);

return 0;

}

C language selection, bubbling, insertion sorting algorithm

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.