| 
            Last change
 on this file since 04db9f6 was             f4e3419d, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago           | 
        
        
          | 
             
restructure paper documents 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.1 KB
           | 
        
      
      
| Line |   | 
|---|
| 1 | #include <stdlib>
 | 
|---|
| 2 | #include "cfa-stack.h"
 | 
|---|
| 3 | 
 | 
|---|
| 4 | forall(otype T) struct stack_node {
 | 
|---|
| 5 |         T value;
 | 
|---|
| 6 |         stack_node(T)* next;
 | 
|---|
| 7 | };
 | 
|---|
| 8 | 
 | 
|---|
| 9 | forall(otype T) void ?{}(stack(T)* s) { (&s->head){ 0 }; }
 | 
|---|
| 10 | 
 | 
|---|
| 11 | forall(otype T) void ?{}(stack(T)* s, stack(T) t) {
 | 
|---|
| 12 |         stack_node(T)** crnt = &s->head;
 | 
|---|
| 13 |         for ( stack_node(T)* next = t.head; next; next = next->next ) {
 | 
|---|
| 14 |                 *crnt = ((stack_node(T)*)malloc()){ next->value }; /***/
 | 
|---|
| 15 |                 stack_node(T)* acrnt = *crnt;
 | 
|---|
| 16 |                 crnt = &acrnt->next;
 | 
|---|
| 17 |         }
 | 
|---|
| 18 |         *crnt = 0;
 | 
|---|
| 19 | }
 | 
|---|
| 20 | 
 | 
|---|
| 21 | forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) {
 | 
|---|
| 22 |         if ( s->head == t.head ) return *s;
 | 
|---|
| 23 |         clear(s);
 | 
|---|
| 24 |         s{ t };
 | 
|---|
| 25 |         return *s;
 | 
|---|
| 26 | }
 | 
|---|
| 27 | 
 | 
|---|
| 28 | forall(otype T) void ^?{}(stack(T)* s) { clear(s); }
 | 
|---|
| 29 | 
 | 
|---|
| 30 | forall(otype T) _Bool empty(const stack(T)* s) { return s->head == 0; }
 | 
|---|
| 31 | 
 | 
|---|
| 32 | forall(otype T) void push(stack(T)* s, T value) {
 | 
|---|
| 33 |         s->head = ((stack_node(T)*)malloc()){ value, s->head }; /***/
 | 
|---|
| 34 | }
 | 
|---|
| 35 | 
 | 
|---|
| 36 | forall(otype T) T pop(stack(T)* s) {
 | 
|---|
| 37 |         stack_node(T)* n = s->head;
 | 
|---|
| 38 |         s->head = n->next;
 | 
|---|
| 39 |         T x = n->value;
 | 
|---|
| 40 |         ^n{};
 | 
|---|
| 41 |         free(n);
 | 
|---|
| 42 |         return x;
 | 
|---|
| 43 | }
 | 
|---|
| 44 | 
 | 
|---|
| 45 | forall(otype T) void clear(stack(T)* s) {
 | 
|---|
| 46 |     for ( stack_node(T)* next = s->head; next; ) {
 | 
|---|
| 47 |                 stack_node(T)* crnt = next;
 | 
|---|
| 48 |                 next = crnt->next;
 | 
|---|
| 49 |                 delete(crnt);
 | 
|---|
| 50 |         }
 | 
|---|
| 51 |         s->head = 0;
 | 
|---|
| 52 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.