-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
34 lines (25 loc) · 894 Bytes
/
LinkedList.java
File metadata and controls
34 lines (25 loc) · 894 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
30
31
32
33
34
public class LinkedList {
Node head; //head of list
//Linked List Node.Class is made static so that main can access it.
static class Node{
int data;
Node next; // next pointer
Node(int d) //Constructor to insert incoming data into node.
{
data=d;
next=null; //Pointing new node head to null;
}
}
public static void main(String args[])
{
LinkedList demolist = new LinkedList(); //Starting with empty list.
demolist.head = new Node(1); //pointing the head of new node
Node second = new Node(2);
Node third = new Node(3);
demolist.head.next=second;
second.next=third;
System.out.println(demolist.head.data);
System.out.println(second.data);
System.out.println(third.data);
}
}