C language for full sorting

Source: Internet
Author: User
// Input 8 12.61 s consumed // input 8 11.72 s consumed remove '-' in the printed array # include <stdio. h> # include <string. h> # include <stdlib. h> # define length 27 int n = 0; void permute (INT [], Int, INT); void swapint (Int & A, Int & B ); void printintarray (INT [], INT); // function implementation void swapint (Int & A, Int & B) {int temp; temp = A; A = B; B = temp;} void printintarray (INT target [], int length) {int I; for (I = 0; I <length; I ++) printf ("% d", target [I]); printf ("\ n");} void permute (INT target [], int begin, int end) {If (begin = END) {printintarray (target, end + 1); N ++; return;} int I; for (I = begin; I <= end; I ++) {swapint (target [begin], target [I]); permute (target, begin + 1, end); swapint (target [begin], target [I]) ;}}// test functions void testpermute () {int Len; scanf ("% d", & Len); int * testcase = (int *) malloc (LEN * sizeof (INT); int I; for (I = 0; I <Len; I ++) testcase [I] = I + 1; permute (testcase, 0, len-1);} // main function void main () {testpermute (); printf ("n = % d", n );}


Related Article

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.