|
2 | 2 | * Do not alter! This code is generated by the sailfishc
|
3 | 3 | * compiler and might/will break if anything changed.
|
4 | 4 | */
|
5 |
| -#include "stdlib/stdlib.h" |
| 5 | + |
| 6 | +#include <stdio.h> |
| 7 | +#include <stdlib.h> |
| 8 | + |
| 9 | +// -------- STDLIB_START ------- // |
| 10 | +void |
| 11 | +print_bool(int i) |
| 12 | +{ |
| 13 | +if (i == 1) |
| 14 | +printf("%s", "true"); |
| 15 | +else |
| 16 | +printf("%s", "false") |
| 17 | +; |
| 18 | +} |
| 19 | +void |
| 20 | +print_flt(float f) |
| 21 | +{ |
| 22 | +printf("%f", f); |
| 23 | +}; |
| 24 | +void |
| 25 | +print_int(int i) |
| 26 | +{ |
| 27 | +printf("%d", i); |
| 28 | +}; |
| 29 | +void |
| 30 | +print_str(char* s) |
| 31 | +{ |
| 32 | +printf("%s", s); |
| 33 | +}; |
| 34 | +// -------- STDLIB_END ------- // |
| 35 | + |
| 36 | +typedef struct _Node_ { |
| 37 | + struct _Node_* next; |
| 38 | + int data; |
| 39 | +} Node; |
| 40 | + |
| 41 | +Node* |
| 42 | +construct_Node(Node* next,int data) |
| 43 | +{ |
| 44 | + Node* a____struct___generated = (Node*)malloc(sizeof(Node)); |
| 45 | + a____struct___generated->next = next; a____struct___generated->data = data; |
| 46 | + return a____struct___generated; |
| 47 | +} |
6 | 48 |
|
7 | 49 | int
|
8 |
| -main() |
| 50 | +has_next(Node* own) |
9 | 51 | {
|
10 |
| - if(1==0) |
| 52 | + int ret = (own->next!=NULL); |
| 53 | + return ret; |
| 54 | +} |
| 55 | +void |
| 56 | +set_next(Node* own, Node* node) |
| 57 | +{ |
| 58 | + own->next = node; |
| 59 | +} |
| 60 | +Node* |
| 61 | +next(Node* own) |
| 62 | +{ |
| 63 | + return own->next; |
| 64 | +} |
| 65 | +int |
| 66 | +data(Node* own) |
| 67 | +{ |
| 68 | + return own->data; |
| 69 | +} |
| 70 | +typedef struct _Stack_ { |
| 71 | + struct _Node_* head; |
| 72 | + int size; |
| 73 | +} Stack; |
| 74 | + |
| 75 | +Stack* |
| 76 | +construct_Stack(Node* head,int size) |
| 77 | +{ |
| 78 | + Stack* a____struct___generated = (Stack*)malloc(sizeof(Stack)); |
| 79 | + a____struct___generated->head = head; a____struct___generated->size = size; |
| 80 | + return a____struct___generated; |
| 81 | +} |
| 82 | + |
| 83 | +int |
| 84 | +is_empty(Stack* own) |
| 85 | +{ |
| 86 | + return (own->size==0); |
| 87 | +} |
| 88 | +int |
| 89 | +size(Stack* own) |
| 90 | +{ |
| 91 | + return own->size; |
| 92 | +} |
| 93 | +int |
| 94 | +peek(Stack* own) |
| 95 | +{ |
| 96 | + int i = 0; |
| 97 | + if(is_empty(own)==1) |
| 98 | +{ |
| 99 | + |
| 100 | +} |
| 101 | +else |
| 102 | +{ |
| 103 | + i = data(own->head); |
| 104 | +} |
| 105 | + |
| 106 | + return i; |
| 107 | +} |
| 108 | +void |
| 109 | +push(Stack* own, Node* node) |
| 110 | +{ |
| 111 | + set_next(node, own->head); |
| 112 | + own->head = node; |
| 113 | + own->size = own->size+1; |
| 114 | +} |
| 115 | +void |
| 116 | +pop(Stack* own) |
| 117 | +{ |
| 118 | + if(is_empty(own)==1) |
11 | 119 | {
|
12 | 120 |
|
| 121 | +} |
| 122 | +else |
| 123 | +{ |
| 124 | + own->head = next(own->head); |
| 125 | + own->size = own->size-1; |
| 126 | +} |
| 127 | + |
| 128 | +} |
| 129 | +void |
| 130 | +print_(Stack* own, Node* node) |
| 131 | +{ |
| 132 | + if(node!=NULL) |
| 133 | +{ |
| 134 | + print_int(data(node)); |
| 135 | + print_str(" "); |
| 136 | + print_(own, next(node)); |
13 | 137 | }
|
14 | 138 | else
|
15 | 139 | {
|
16 | 140 |
|
17 | 141 | }
|
18 | 142 |
|
19 | 143 | }
|
| 144 | +void |
| 145 | +print(Stack* own) |
| 146 | +{ |
| 147 | + print_str("Stack contents: "); |
| 148 | + print_(own, own->head); |
| 149 | + print_str("\n"); |
| 150 | +} |
| 151 | +int |
| 152 | +main() |
| 153 | +{ |
| 154 | + Node* a = construct_Node(NULL,10); |
| 155 | + Node* b = construct_Node(NULL,20); |
| 156 | + Node* c = construct_Node(NULL,30); |
| 157 | + Node* d = construct_Node(NULL,40); |
| 158 | + Node* e = construct_Node(NULL,50); |
| 159 | + Stack* s = construct_Stack(NULL,0); |
| 160 | + push(s, a); |
| 161 | + push(s, b); |
| 162 | + push(s, c); |
| 163 | + print(s); |
| 164 | + print_str("Size: "); |
| 165 | + print_int(size(s)); |
| 166 | + print_str("\tTop: "); |
| 167 | + print_int(peek(s)); |
| 168 | + print_str("\n"); |
| 169 | + pop(s); |
| 170 | + pop(s); |
| 171 | + pop(s); |
| 172 | + pop(s); |
| 173 | + pop(s); |
| 174 | + print_str("Size: "); |
| 175 | + print_int(size(s)); |
| 176 | + print_str("\tTop: "); |
| 177 | + print_int(peek(s)); |
| 178 | + print_str("\n"); |
| 179 | + push(s, d); |
| 180 | + push(s, e); |
| 181 | + push(s, c); |
| 182 | + push(s, b); |
| 183 | + print(s); |
| 184 | +} |
0 commit comments