int main() { int a[5]; for(int i=0;i<5;i++) scanf("%d",&a[i]); assertSorted(a,5); display(a,5); }
void add_ifrs_to_local_state(int num_new_ifrs, unsigned long *new_ifrs, int write) { int *curIFRVar; int *maxIFRVar; unsigned long **myIFRVars; if (write) { curIFRVar = &curWIFRVar; maxIFRVar = &maxWIFRVar; myIFRVars = &myWIFRVars; } else { curIFRVar = &curRIFRVar; maxIFRVar = &maxRIFRVar; myIFRVars = &myRIFRVars; } /* Expand the array if necessary. */ while (*curIFRVar + num_new_ifrs > *maxIFRVar) { *myIFRVars = (unsigned long *) realloc(*myIFRVars, 2 * (*maxIFRVar) * sizeof(unsigned long)); if (!(*myIFRVars)) { fprintf(stderr, "[IFRit] ERROR: Could not allocate more memory for weak monitors\n"); exit(1); } *maxIFRVar = (*maxIFRVar) * 2; } /* Insert the IFRs into the array. */ int v; for (v = 0; v < num_new_ifrs; v++){ insertElement(*myIFRVars, *curIFRVar, new_ifrs[v]); *curIFRVar = (*curIFRVar) + 1; assertSorted(*myIFRVars, *curIFRVar); } }
/* BEGIN TEMPLATE */ void solve() { /* BEGIN SOLUTION */ int afterBlue=0; int beforeWhite=getSize()-1; int beforeRed=getSize()-1; while (afterBlue <= beforeWhite) { switch (getColor(afterBlue)) { case BLUE: afterBlue++; break; case WHITE: swap(afterBlue, beforeWhite); beforeWhite --; break; case RED: swap(afterBlue, beforeWhite); swap(beforeRed, beforeWhite); beforeWhite--; beforeRed--; } } assertSorted(); /* END SOLUTION */ }