Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -1,2 +1,3 @@
|
|||
LEA userStack,A0 ;initialize the user stack, points to a memory address in user RAM. Only do this once!
|
||||
MOVEM.L D0-D3,-(A0) ;moves the full 32 bits of registers D0,D1,D2,D3 into the address pointed by A0, with pre-decrement
|
||||
LEA userStack,A0 ;initialize the user stack, points to a memory address in user RAM. Only do this once!
|
||||
MOVEM.L D0-D3,-(A0) ;moves the full 32 bits of registers D0,D1,D2,D3 into the address pointed by A0,
|
||||
;with pre-decrement
|
||||
|
|
|
|||
15
Task/Stack/Ballerina/stack-1.ballerina
Normal file
15
Task/Stack/Ballerina/stack-1.ballerina
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import ballerina/io;
|
||||
|
||||
public function main() {
|
||||
int[] stack = [];
|
||||
stack.push(1);
|
||||
stack.push(2);
|
||||
io:println("Stack contains ", stack);
|
||||
io:println("Number of elements in stack = ", stack.length());
|
||||
int item = stack.pop();
|
||||
io:println(item, " popped from the stack");
|
||||
io:println("Last element is now ", stack[stack.length() - 1]);
|
||||
stack.removeAll();
|
||||
io:println("Stack cleared");
|
||||
io:println("Is stack now empty? ", stack.length() == 0 ? "yes" : "no");
|
||||
}
|
||||
53
Task/Stack/Ballerina/stack-2.ballerina
Normal file
53
Task/Stack/Ballerina/stack-2.ballerina
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import ballerina/io;
|
||||
|
||||
class Stack {
|
||||
private any[] s = [];
|
||||
|
||||
function push(any a) {
|
||||
self.s.push(a);
|
||||
}
|
||||
|
||||
function length() returns int {
|
||||
return self.s.length();
|
||||
}
|
||||
|
||||
function isEmpty() returns boolean {
|
||||
return self.length() == 0;
|
||||
}
|
||||
|
||||
function pop() returns any? {
|
||||
if !self.isEmpty() {
|
||||
return self.s.pop();
|
||||
}
|
||||
return ();
|
||||
}
|
||||
|
||||
function peek() returns any? {
|
||||
if !self.isEmpty() {
|
||||
return self.s[self.length() - 1];
|
||||
}
|
||||
return ();
|
||||
}
|
||||
|
||||
function clear() {
|
||||
self.s.removeAll();
|
||||
}
|
||||
|
||||
function toString() returns string {
|
||||
return self.s.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public function main() {
|
||||
Stack s = new;
|
||||
s.push(1);
|
||||
s.push(2);
|
||||
io:println("Stack contains ", s);
|
||||
io:println("Number of elements in stack = ", s.length());
|
||||
any item = s.pop();
|
||||
io:println(item, " popped from the stack");
|
||||
io:println("Last element is now ", s.peek());
|
||||
s.clear();
|
||||
io:println("Stack cleared");
|
||||
io:println("Is stack now empty? ", s.isEmpty() ? "yes" : "no");
|
||||
}
|
||||
|
|
@ -2,33 +2,37 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
/* to read expanded code, run through cpp | indent -st */
|
||||
#define DECL_STACK_TYPE(type, name) \
|
||||
#define DECL_STACK_TYPE(type, name) \
|
||||
typedef struct stk_##name##_t{type *buf; size_t alloc,len;}*stk_##name; \
|
||||
stk_##name stk_##name##_create(size_t init_size) { \
|
||||
stk_##name s; if (!init_size) init_size = 4; \
|
||||
s = malloc(sizeof(struct stk_##name##_t)); \
|
||||
if (!s) return 0; \
|
||||
s->buf = malloc(sizeof(type) * init_size); \
|
||||
if (!s->buf) { free(s); return 0; } \
|
||||
s->len = 0, s->alloc = init_size; \
|
||||
return s; } \
|
||||
int stk_##name##_push(stk_##name s, type item) { \
|
||||
type *tmp; \
|
||||
if (s->len >= s->alloc) { \
|
||||
tmp = realloc(s->buf, s->alloc*2*sizeof(type)); \
|
||||
if (!tmp) return -1; s->buf = tmp; \
|
||||
s->alloc *= 2; } \
|
||||
s->buf[s->len++] = item; \
|
||||
return s->len; } \
|
||||
type stk_##name##_pop(stk_##name s) { \
|
||||
type tmp; \
|
||||
if (!s->len) abort(); \
|
||||
tmp = s->buf[--s->len]; \
|
||||
if (s->len * 2 <= s->alloc && s->alloc >= 8) { \
|
||||
s->alloc /= 2; \
|
||||
s->buf = realloc(s->buf, s->alloc * sizeof(type));} \
|
||||
return tmp; } \
|
||||
void stk_##name##_delete(stk_##name s) { \
|
||||
\
|
||||
stk_##name stk_##name##_create(size_t init_size) { \
|
||||
stk_##name s; if (!init_size) init_size = 4; \
|
||||
s = malloc(sizeof(struct stk_##name##_t)); \
|
||||
if (!s) return 0; \
|
||||
s->buf = malloc(sizeof(type) * init_size); \
|
||||
if (!s->buf) { free(s); return 0; } \
|
||||
s->len = 0, s->alloc = init_size; \
|
||||
return s; } \
|
||||
\
|
||||
int stk_##name##_push(stk_##name s, type item) { \
|
||||
type *tmp; \
|
||||
if (s->len >= s->alloc) { \
|
||||
tmp = realloc(s->buf, s->alloc*2*sizeof(type)); \
|
||||
if (!tmp) return -1; s->buf = tmp; \
|
||||
s->alloc *= 2; } \
|
||||
s->buf[s->len++] = item; \
|
||||
return s->len; } \
|
||||
\
|
||||
type stk_##name##_pop(stk_##name s) { \
|
||||
type tmp; \
|
||||
if (!s->len) abort(); \
|
||||
tmp = s->buf[--s->len]; \
|
||||
if (s->len * 2 <= s->alloc && s->alloc >= 8) { \
|
||||
s->alloc /= 2; \
|
||||
s->buf = realloc(s->buf, s->alloc * sizeof(type));} \
|
||||
return tmp; } \
|
||||
\
|
||||
void stk_##name##_delete(stk_##name s) { \
|
||||
free(s->buf); free(s); }
|
||||
|
||||
#define stk_empty(s) (!(s)->len)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
stack[] = [ ]
|
||||
proc push v . .
|
||||
proc push v .
|
||||
stack[] &= v
|
||||
.
|
||||
func pop .
|
||||
lng = len stack[]
|
||||
if lng = 0
|
||||
return 0
|
||||
.
|
||||
if lng = 0 : return 0 / 0
|
||||
r = stack[lng]
|
||||
len stack[] -1
|
||||
return r
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue