Beispiel #1
0
int main() {
  char now[101];
  strcpy(now, "http://www.acm.org/");
  for(;;) {
    char s[71];
    scanf("%s", s);
    if (strcmp(s, "VISIT") == 0) {
      scanf("%s", s);
      printf("%s\n", s);
      b_push(now);
      strcpy(now, s);
      empty();
    } else if (strcmp(s, "BACK") == 0) {
      char *url=b_pop();
      if (strcmp(url, "Ignored")!=0) {
        f_push(now);
        strcpy(now, url);
      }
      printf("%s\n", url);
    } else if (strcmp(s, "FORWARD") == 0) {
      char *url=f_pop();
      if (strcmp(url, "Ignored")!=0) {
        b_push(now);
        strcpy(now, url);
      }
      printf("%s\n", url);
    } else {
      return 0;
    }
  }
}
int main(void) {
    struct stack *balancer = stack_new();
    for (int i = 0; i < 10; i++) {
        b_push(balancer, node_new((void *)0xbeef), 2);
        printf("after push, n stacks in the balancer: %d\n",balancer->n_items);
    }

    for (int i = 0; i < 10; i++) {
        struct node *n = b_pop(balancer);
        printf("after pop, n stacks in the balancer: %d, val: %p\n",balancer->n_items, n->value);
    }

}