annotate paper/src/singleLinkedStack.c @ 116:ed6719c301fc

Update slide
author atton <atton@cr.ie.u-ryukyu.ac.jp>
date Mon, 13 Feb 2017 17:31:45 +0900
parents c0693ad89f04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
65
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 __code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) {
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 Element* element = new Element();
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 element->next = stack->top;
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 element->data = data;
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 stack->top = element;
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 goto next(...);
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 }
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 __code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 if (stack->top) {
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 data = stack->top->data;
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 stack->top = stack->top->next;
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 } else {
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 data = NULL;
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 }
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 goto next(data, ...);
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 }
c0693ad89f04 Add single linked stack
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18