Ali pen questions, ordered sequence of sequential output.

Source: Internet
Author: User

According to their own thinking simple write a bit, a lot of communication.

#include "stdafx.h" int insertinorder (int *a,int num,int len) {//This method can be improved a lot, insert data, and then sort. int Position;if (a[0]==0) {A[0] = Num;position = 1;} for (int i = 0; i < len-1;i++) {if (Num>a[i] && num<a[i + 1]) {position = i + 2;for (int j = len-1; J > i+1;j--) {A[j] = a[j-1];} A[I+1] = num;break;} if (Num>a[i] && 0 = = a[i + 1]) {position = i + 2;a[i + 1] = Num;break;}} return position;} int _tmain (int argc, _tchar* argv[]) {int a[100] = {0};int b[] = {1, 2, 5, 8, ten, 4, 3, 6, 9, 7};int count = 0;int i = 0 int position;//at the beginning of the position to start from 1, but also with a lot of inconvenience. int len = sizeof (b)/sizeof (int), for (i = 1; I <= len; i++) {position = Insertinorder (a,b[i-1],i); if (count = = (Positio n-1) && Position = = A[position-1]) {printf ("%d,", a[position-1]); count++;for (int j = position + 1; J <= L En J + +) {if (a[j-1]==0) {break;} if (count = = (j-1) && j = = A[j-1]) {count++;//i++;p rintf ("%d,", a[j-1]);}} printf ("\ n");}} return 0;}

Ali pen questions, ordered sequence of sequential output.

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.