Posts

Showing posts with the label Data Structure

ArrayList vs LinkedList

Image
Both ArrayList vs LinkedList, are the implementation of List interface in java. But they have different use cases and characteristics. CustomList.java public interface CustomList { int size () ; boolean isEmpty () ; void add (String value) ; void add ( int index , String value) ; void remove ( int index) ; String get ( int index) ; } CustomLinkedList.java package com.godel.ds.implementation ; import com.godel.ds.interfaces.CustomList ; @SuppressWarnings ( "unchecked" ) public class CustomLinkedList implements CustomList { Node head ; int size ; public CustomLinkedList () { this . head = null; this . size = 0 ; } @Override public int size () { return size ; } @Override public boolean isEmpty () { return size == 0 ; } @Override public void add (String value) { Node newNode = new Node<>(value) ; if ( size == 0 ) this . head = newNode ; ...