what the difference between methods push() and add() since this ones do the same stuff - push the value into linked list via constructor, but add() doesn't add the value
public class LinkedList {
static class Node {
int value;
Node next;
Node(int value){
this.value = value;
next = null; }
};
Node head;
Node next;
void push(Node node){
Node newnode = node;
newnode.next = head;
head = newnode; }
void add(Node node, Node head){addNode(node,head);}
void addNode(Node node, Node head){
Node newnode = node;
newnode.next = head;
head = newnode; }
/* Function to print linked list */
void printlist(Node head){
while(head != null){
System.out.println(head.value + " ");
head = head.next; }
}
// Driver program to test above functions
public static void main(String args[])
{
LinkedList list = new LinkedList();
list.head = null;
list.head = new Node(5);
list.push(new Node(6));
list.add(new Node(3), list.head);
list.push(new Node(7));
list.printlist(list.head);
}
}