-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkList.java
More file actions
executable file
·29 lines (21 loc) · 967 Bytes
/
LinkList.java
File metadata and controls
executable file
·29 lines (21 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class LinkList{
Node head; // Head is the pointer which points to the first element in the list
static class Node{ // This class represents one node in the link list
int data; // data in each node
Node next; // next pointer posints to the next element
public Node(int d){ // Prameterised contructor which inilizes the node
data=d;
next=null;
}
}
public static void main(String[] args){
LinkList list = new LinkList(); // Initilize the list
Node first = new Node(1); // Creating 1st node
Node second = new Node(2); // create 2nd node
Node third = new Node(3); // create third node
list.head = first; // connecting head to first node
first.next=second; // connecting first.next pointer to second node
second.next=third; // connecting second.next pointer to third node
System.out.println("Success full in creating nodes "+list.head.data+" "+second.data+" "+third.data); // printng the nodes
}
}