void add(struct oper op, char finish_rem, int curline) { if (finish_rem == 'f') { if (op.type == LEFT) pusho(&o, op); else if (sizeo(&o) == 0) pusho(&o, op); else { while (sizeo(&o) > 0 && topo(&o).type != LEFT && priority[topo(&o).type] >= priority[op.type]) { struct command* newcom = (struct command*)malloc(sizeof(struct command)); newcom->input = newcom->output = NULL; newcom->type = types[topo(&o).type]; if (sizec(&s) < 2) printError(curline); newcom->u.command[1] = topc(&s); popc(&s); newcom->u.command[0] = topc(&s); popc(&s); pushc(&s, newcom); popo(&o); } if (op.type == RIGHT && topo(&o).type == LEFT) popo(&o); else pusho(&o, op); if (op.type == RIGHT) { struct command* ncom = (struct command*)malloc(sizeof(struct command)); ncom->input = ncom->output = NULL; ncom->type = SUBSHELL_COMMAND; ncom->u.subshell_command = topc(&s); popc(&s); pushc(&s, ncom); } } } else if (finish_rem == 't') { while (sizeo(&o) > 0) { struct command* newcom = (struct command*)malloc(sizeof(struct command)); newcom->input = newcom->output = NULL; newcom->type = types[topo(&o).type]; if (sizec(&s) < 2) printError(curline); newcom->u.command[1] = topc(&s); popc(&s); newcom->u.command[0] = topc(&s); popc(&s); pushc(&s, newcom); popo(&o); } } }
main() { int i, j, p[50], p1[50]; printf("Data:\n"); for (i = 0; i < 5; i++) { /* 生成一些无序数据*/ for (j = 0; j < 10; j++) { p[10 * i + j] = 20 + 10 * i - j ; p1[10 * i + j] = p[10 * i + j]; printf("%d ", p[10 * i + j]); } printf("\n"); } printf("Quick Sort:\n"); /* 快速排序的结果*/ qcks(p, 0, 49); for (i = 0; i < 5; i++) { for (j = 0; j < 10; j++) { printf("%d ", p[10 * i + j]); } printf("\n"); } printf("Bubble Sort:\n"); /* 气泡排序的结果*/ popo(p, 50); for (i = 0; i < 5; i++) { for (j = 0; j < 10; j++) { printf("%d ", p[10 * i + j]); } printf("\n"); } }