Insert a node at the head of a linked list using Java

/*
  Insert Node at the beginning of a linked list
  head pointer input could be NULL as well for empty list
*/
/*
  Node is defined as
  class Node {
     int data;
     Node next;
  }
*/

Node Insert(Node head,int x) {
    Node node=new Node();
    node.data=x;
    node.next=head;
    return node;
}

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations