-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedlist.java
More file actions
52 lines (45 loc) · 945 Bytes
/
Linkedlist.java
File metadata and controls
52 lines (45 loc) · 945 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Node{
int data;
Node next;
Node(int data){
this.data = data;
this.next = null;
}
}
class Main{
Node head;
void append(int data)
{
Node nn = new Node(data);
if(head == null)
{
head = nn;
return;
}
Node temp = head;
while(temp.next != null) temp = temp.next;
temp.next = nn;
}
void display()
{
Node temp = head;
while(temp != null)
{
System.out.print(temp.data+" ");
temp = temp.next;
}
System.out.println();
}
public static void main(String args[])
{
Main list = new Main();
Main list2 = new Main();
list2.append(100);
list.append(10);
list.append(20);
list.append(30);
list.append(40);
list.display();
list2.display();
}
}