Latest from community today
function helloWorld() {
console.log('Hello, World');
}
helloWorld();
public class MyNode {
private int Value;
private MyNode Next;
public void setValue(int value) {
Value = value;
}
public MyNode getNext() {
return Next;
}
public int getValue() {
return Value;
}
public void setNext(MyNode next) {
Next = next;
}
}
public class MyLinkedList {
private MyNode First = new MyNode();
private MyNode Last = First;
private int size = 0;
public void addFirst(int value) {
if (size == 0) {
First.setValue(value);
}
if (size == 1) {
this.Last = new MyNode();
this.Last.setValue(First.getValue());
First.setValue(value);
First.setNext(this.Last);
} else {
MyNode newNode = new MyNode();
newNode.setValue(value);
newNode.setNext(First);
First = newNode;
}
size++;
}
public void addLast(int value) {
if (size == 0) {
First.setValue(value);
}
if (size == 1) {
this.Last = new MyNode();
this.Last.setValue(value);
First.setNext(this.Last);
} else {
MyNode newNode = new MyNode();
newNode.setValue(value);
Last.setNext(newNode);
Last = newNode;
}
size++;
}
public void deleteLast() {
if (size < 1) throw new IllegalArgumentException();
if (size != 1) {
MyNode previousToLastNode = First;
while (previousToLastNode.getNext() != Last) {
previousToLastNode = previousToLastNode.getNext();
}
Last = previousToLastNode;
Last.setNext(null);
}
size--;
}
public void deleteFirst() {
if (size < 1) throw new IllegalArgumentException();
if (size != 1) {
MyNode nextNode = First.getNext();
First.setValue(nextNode.getValue());
First.setNext(nextNode.getNext());
}
size--;
}
public boolean contains(int value) {
MyNode currentNode = First;
for (int i = 0; i < size; i++) {
if (currentNode.getValue() == value) return true;
currentNode = currentNode.getNext();
}
return false;
}
public int indexOf(int value) {
int index = 0;
MyNode currentNode = First;
for (int i = 0; i < size; i++) {
if (currentNode.getValue() == value) return index;
currentNode = currentNode.getNext();
index++;
}
return -1;
}
public int size() {
return size;
}
public void print() {
if (size > 0) {
MyNode currentNode = First;
for (int i = 0; i < size; i++) {
System.out.println(currentNode.getValue());
currentNode = currentNode.getNext();
}
}
}
}
def say_hello():
print ('Hello, World')
for i in range(5):
say_hello()
def helloWorld():
print ('Hello, World')
for i in range(5):
helloWorld()
function Add() {
return a+b;
}
console.log (Add(2,3);)
function helloWorld() {
console.log('Hello, World');
}
helloWorld();
package main
import "fmt"
func main(){
arr := []int{0, 1, 2, 3, 4}
arr[0] = 1
arr = append(arr, 5)
newArr := append(arr, 6)
newArr[0] = 2
fmt.Println("arr:", arr, "cap:", cap(arr))
fmt.Println("newArr:", newArr, "cap:", cap(newArr))
}
function helloWorld() {
console.log('Hello, World');
}
helloWorld();
def say_hello():
print ('Hello, World')
for i in range(5):
say_hello()
function helloWorld() {
console.log('Hello, World');
}
helloWorld();