public void addAtBegin(int item){ Node nn = new Node(); nn.data = item; //attach new node to the previous node if(this.size >= 1) nn.next = head; else this.tail = nn; //shift head of previous node to the ned node this.head = nn; this.size++; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter