# All# python# wedfg# scope variable# interview# lexical environment# javascript# #algorithm# hoisting# good# print# java# coding shortcut# competitive coding# shorthand# loop tricks# sample# #c# gambling# primitives# algoritms# arrow-functions# javascriptintro# usefullinks# technical round# project# beetroot# reverse# array# copy# collection# test# i am printing hello world# #class# #js# #interview# map# lodash# scoping# async# prime numbers# python journey# weather app# easy way to remove duplicates# # #javascript# pho# possible ways of calculator app# var a = 10 function f(){ console.log(a) } f(); console.log(a);# gg# bank# as# palindrome# hello world basic intro# #python# pattern program# nodejs# key# concept of var, let and const# #helloworld# please give better ans# php# hello world# code review# string# d# javascript functions# fusionauth# c++# helloworld# hello, world# forloop# slice# adding two numbers# diamond# @python3# #python3# arraylistcourceimplemetnation# cpp

Latest from community today

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();
            }
        }
    }

}
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))
}

Featured content