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++; }
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++; }