Skip to content

Instantly share code, notes, and snippets.

View vin18's full-sized avatar

Vinit Raut vin18

View GitHub Profile
// Function to delete node from a linked list
public static Node<Integer> delete(Node<Integer> data, int pos) {
if (head == null) {
return head;
}
int i = 0;
if (pos == 0) {
return head.next;
}
Node<Integer> temp = head;
// Function to insert node in a linked list
public static Node<Integer> insert(Node<Integer>, int data, int pos) {
Node<Integer> newNode = new Node<Integer>(data);
if (pos == 0) {
newNode.next = head;
return newNode;
}
Node<Integer> temp = head;
int i = 0;
while (temp != null && i < pos - 1) {
// Function to print a linked list
public static void printList(Node<Integer> head) {
if (head == null) {
return;
}
while (head != null) {
System.out.println(head.data);
head = head.next;
}
}
// Function to take input of a linked list
public static Node<Integer> takeInput() {
Scanner s = new Scanner(System.in);
Node<Integer> head = null, tail = null;
int data = s.nextInt();
while (data != -1) {
Node<Integer> newNode = new Node<Integer>(data);
if (head == null) {
head = newNode;
tail = newNode;
Node<Integer> node1 = new Node<Integer>(10);
public class Node<T> {
T data;
Node<T> next;
Node(T data) {
this.data = data;
next = null;
}
}
public class Node<T> {
T data;
Node<T> next;
Node(T data) {
this.data = data;
next = null;
}
}