1 #include<stdio.h>
 2 typedef struct{
 3     int array[50];
 4     int top;
 5 }SeqStack;
 6 void Inite(SeqStack*S)
 7 {
 8     S->top=-1; 
 9 }
10 int Pop(SeqStack*S)
11 {
12     int e;
13     e=S->array[S->top]; 
14     S->top--;
15     return e;
16 }
17 void Push(SeqStack*S,int e)
18 {
19     S->top++;
20     S->array[S->top]=e; 
21 }
22 int Empty(SeqStack*S)
23 {
24     if(S->top==-1)return 1;
25     else return 0;
26 }
27 void Classify(SeqStack*S,int*train,int n)
28 {
29     SeqStack *S1,S2;
30     S1=S;
31     Inite(&S2);
32     for(int i=0;i<n;i++)
33     {
34         if(train[i]==0) Push(S1,train[i]);
35         else Push(&S2,train[i]);
36     }
37     while(!Empty(&S2))
38     Push(S1,Pop(&S2));
39 }
40 void Order(SeqStack*S)
41 {
42     for(int i=0;i<=S->top;i++)
43     printf("%d ",S->array[i]);
44 }
45 int main()
46 {
47     SeqStack S1;//S1存放结果
48     int train[50];
49     int n;
50     Inite(&S1);
51     scanf("%d",&n);
52     for(int i=0;i<n;i++)
53     scanf("%d",&train[i]);
54     Classify(&S1,train,n);
55     Order(&S1);
56     return 0;
57 }