Home > Back-end >  Pta simplified insertion sort which has a problem, look at this said my section error
Pta simplified insertion sort which has a problem, look at this said my section error

Time:12-24

#include

Int main ()
{
Int b, I, j, m, n, k, x.
The scanf (" % d ", & amp; N);
Int a [n].
for(i=0; i{
The scanf (" % d ", & amp; A [I]);
}
The scanf (" % d ", & amp; X);
for(i=0; i{
If (x> A [I])
{
printf("%d ",a[i]);
}
If (x{
Printf (" % d ", x);
M=I;
break;
}
}
For (I=m; i{
printf("%d ",a[i]);
}
return 0;
}

CodePudding user response:

 # include & lt; stdio.h> 
#include
# define MAX_SIZE 10


Void insert_sort (int * arr, int len, int new_num)
{
Int I=0, j=0;

While (I & lt; Len) {
If (arr [I] & gt; New_num) {
//printf (" % d++ \ n ", arr [I]);
For (j=len; J & gt; i; J -)
Arr=arr [j] [1];
break;
}
i++;
}

Arr [I]=new_num;

}


Void print_array (int * arr, int len)
{
int i;

for (i=0; I & lt; Len. I++)
Printf (" % d % c ", arr [I], (I + 1) % 10==0? '\ n' : ');
Putchar (10);
}

Int main ()
{
If # 1

Int n, I;
Int * array, TMP, new_num;

The scanf (" % d ", & amp; N);

If (n & gt;=MAX_SIZE)
N=MAX_SIZE;

Array=(int *) malloc (sizeof (int) * n);
if (! Array)
return -1;

for (i=0; I & lt; n; I++) {
The scanf (" % d ", & amp; TMP);
Insert_sort (array, I, TMP);
}
Print_array (array, n);

The scanf (" % d ", & amp; New_num);

Insert_sort (array, n, new_num);

Print_array (array, n + 1);
# the else
Int b, I, j, m, n, k, x.
The scanf (" % d ", & amp; N);
Int a [n].
for(i=0; i{
The scanf (" % d ", & amp; A [I]);
}
The scanf (" % d ", & amp; X);
for(i=0; i{
If (x> A [I])
{
printf("%d ",a[i]);
}
If (x
{
Printf (" % d ", x);
M=I;
break;
}
}
For (I=m; i{
printf("%d ",a[i]);
}
# endif
return 0;
}

For your reference ~
  • Related