Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
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");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue