topic:
Table stored in a linear vector A [arrsize] elenum front of component, and the order is incremented. Inserts x into place on the linear table, in order to maintain orderly linear form.
Wherein arrsize represents the size of the array A. elenum representative of the number of elements.
Sample O: Group 1
Sample input:
7 // Representative arrsize size
1234567 // input value A vector
value of 5 // elenum
6 // value into the element x
Sample Output:
12345667
Summary:
Sequence table storage, insertion function, selection sort.
Source:
#include <stdio.h> #include <stdlib.h> #define MAXSIZE 1024 typedef struct seqlist { int data[MAXSIZE]; int last; }SeqList; SeqList *init_SeqList() { SeqList *L; L=(SeqList *)malloc(sizeof(SeqList)); L->last=-1; return L; } void Insert(SeqList *L,int ele,int dat) { int i,j,temp; if(ele>=L->last) printf("error"); else { for(j=L->last;j>ele-1;j--) L->data[j+1]=L->data[j]; L->data[j+1]=dat; L->last++; } for(i=L->last;i>0;i--) { if(L->data[i] < L->data[i-1]) { temp=L->data[i]; L->data[i]=L->data[i-1]; L->data[i-1]=temp; } } } void Display(SeqList *L,int n) { int i; for(i=0;i<n;i++) printf("%d ",L->data[i]); } int main() { SeqList *A; int x,elenum; int i,n,arrsize; A=init_SeqList(); scanf("%d",&arrsize); for(i=0;i<arrsize;i++) { scanf("%d",&A->data[i]); A->last++; } scanf("%d",&elenum); scanf("%d",&x); Insert(A,elenum-1,x); printf("\n"); Display(A,A->last+1); return 0; }
test:
Sample input:
5 // Representative arrsize size
34567 // input value A vector
value of 4 // elenum
2 // value into the element x
Sample Output:
234,567
Sample input:
10 // Representative arrsize size
2346789102122 // input value A vector
value of 8 // elenum
5 // value into the element x
Sample Output:
2346789102122
to sum up:
Bloggers a little lazy, but it would be better for Japan