Rank All integers in the array before the negative number.

Source: Internet
Author: User
Original question

Store any n integers in array A, write programs, and rank all integers before all negative numbers.

Ideas

The question is super watery, and the code is directly written.

Implementation Code
/*************************************** * *********************************> File Name: testmain. c> author: krischou> mail: [email protected]> created time: mon 18 Aug 2014 12:26:34 am CST ********************************* ***************************************/ # include <stdio. h> # include <stdlib. h> # include <string. h> # include <time. h> void print (int * arr, int N); void partion (int * arr, int N); int Ma In (INT argc, char * argv []) {int size = atoi (argv [1]); int * arr = (int *) calloc (size, sizeof (INT); int index; srand (Time (null); For (Index = 0; index <size; index ++) {If (RAND () % 2 = 0) {arr [Index] = rand () % 100;} else {arr [Index] =-rand () % 100 ;}} print (ARR, size); partion (ARR, size); print (ARR, size); Return 0;} void print (int * arr, int N) {int index; for (Index = 0; index <n; index ++) {printf ("% 4D ", arr [Index]);} printf (" \ n ");}/*** if low ++ makes low and high meet, the left element of low is already in the correct position, and the right element of high (including high) is also in the correct position. Finish. * If high -- makes low and high meet each other, the low left element (including low) is already in the correct position, and the high right element is also in the correct position. Finish. */Void partion (int * arr, int N) {int low = 0; int high = n-1; int TMP; while (low 

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.